tags: spring
<! - Manual assignment ->
<bean id="student1" class="com.yq.shoudong.Student">
<property name="name" value="yq"/>
<property name="age" value="10"/>
</bean>
<bean id="school1" class="com.yq.shoudong.School">
<property name="name" value="yq"/>
<property name="address" value="Nanjing"/>
<! - The reference type assignment REF is consistent with the ID of the assignment bean ->
<property name="student" ref="student1"/>
</bean>
<! - BYNAME Automatic Injection ->
<! - Reference type automatic injection, Spring framework can assign a reference type according to certain rules ->
<! - Using rules are commonly used by BYNAME BYTYPE
1. BYNAME (according to Name Injection): The reference type attribute name in the Java class is the same as the ID name of the (configuration file) <bean> in the Spring container.
And the data type is consistent, Spring can assign value reference types
Grammar rules:
<bean id=xxx class=xxx autowired=byName/>
-->
<bean id="student" class="com.yq.autowired.Student">
<property name="name" value="yq"/>
<property name="age" value="10"/>
</bean>
<bean id="school" class="com.yq.autowired.School" autowire="byName">
<property name="name" value="yq"/>
<property name="address" value="Nanjing"/>
</bean>
<! - ByType Automatic Injection ->
<! - Injecting type injecting, only one type injection ->
<! - 1, directly according to type ->
<!-- <bean id="studentByType1" class="com.yq.autowiredByType.Student">-->
<!-- <property name="name" value="yx"/>-->
<!-- <property name="age" value="10"/>-->
<!-- </bean>-->
<! - 2, injecting sub-type ->
<!-- <bean id="Monitor" class="com.yq.autowiredByType.Monitor">-->
<! - <property name = "name" value = "Sub Type Inject" /> ->
<!-- <property name="age" value="10"/>-->
<!-- </bean>-->
<! - 3, press the implantation ->
<bean id="aClass" class="com.yq.autowiredByType.ClassImp">
<property name="id" value="Implementation"/>
</bean>
<bean id="schoolByType1" class="com.yq.autowiredByType.School" autowire="byType">
<property name="name" value="nanda"/>
<property name="address" value="Nanjing"/>
</bean>
1. Let it call the construction method of the two parameters configured by itself 1.1 Introduction to the use of attributes 1. Commonly used name+value, note that the id name here cannot be the same a...
Bean automatic assembly is divided into 5 types: 1.byName attribute name; 2. byType attribute type; 3. Constructor construction method assembly; 4. autodetect checks the internal selection of byType o...
Use the Autowire tab to complete the automatic injection of Beans First of all, we have the following two classes: AutoWire = "byname", injecting according to the member variable name AutoWi...
This is the location map of the file First, automatic assembly Add to CONTEXT in the bean file The bean here is a lot, I want to know all the code, see the column of Spring about Spring in my account,...
Dependency injection Rely: refers to the creation of the bean object depends on the container. Dependent resources of bean objects Injection: Refers to the resources dependent on the bean object, set ...
Simple attribute assignment: First create a calss object, write the attribute values we need, and write the set method 2. Create a bean tag in the xml file, and assign a value to the target class th...
autowire Attribute Value is automatic assembly and three as follows: the byType (depending on the type automatic assembly): If the IOC plurality of containers consistent with the target type Bean Bean...
Spring IOC container can be automatically assembled Bean. Needs to do is to specify autowire properties in the automatic assembly mode. the byType (depending on the type automatic assembly): If the IO...
BEAN's automatic assembly Automatic assembly, Spring meets Bean dependencies autowire Spring will automatically find in the context and automatically assemble properties to beans There are three assem...
Di: dependency injection Dependence: The creation of the bean object is dependent on the container. Inject: All properties in the bean object are injected by the container. First, the core of Di injec...