1.bean Label
In spring, to configure a bean in XML, you must use the bean tag, which contains two important attributes:
ID: The bean tag is unique within the container
Class type of Class:bean
Scope: Represents the number of instances of the bean, which by default is a singleton.
2.property Label
The property is a child tag of the bean, which can be injected into the attributes of the bean instance, with the following important attributes:
Name: The property of the corresponding class
Value: The original value to inject the class property
Ref: The ID of the reference bean to inject the class property into
The property can contain the bean's label, so that the bean under the property is the internal bean, the internal bean can only be used internally, and the outside cannot reference the internal bean.
The child tags of the property can be collection labels, which include list,map,properties, etc., and their specific usage can be referenced in the spring Help documentation.
3.constructor-arg Label
Used to construct a bean object for injection.
4.null Label
5. Special characters
<! [cdata[text content]]>
6. Here is an example:
<!--Configure bean--> with a full class name
<bean id= "Person1" class= "Com.lkj.study.beanConfigs.Person" >
</bean>
<!--property injection by property setting Method--
<bean id= "Person2" class= "Com.lkj.study.beanConfigs.Person" scope= "prototype" >
<property name= "name" value= "Zhang San" ></property>
<property name= "Age" >
<value>123</value>
</property>
</bean>
<!--property Injection by construction Method--
<bean id= "Person3" class= "Com.lkj.study.beanConfigs.Person" scope= "prototype" >
<constructor-arg value= "Zhangsan" ></constructor-arg>
<constructor-arg value= "></constructor-arg>"
</bean>
<bean id= "Person4" class= "Com.lkj.study.beanConfigs.Person" scope= "prototype" >
<constructor-arg ><null></null></constructor-arg>
<constructor-arg value= "></constructor-arg>"
</bean>
Injection of special characters
<bean id= "Person5" class= "Com.lkj.study.beanConfigs.Person" scope= "prototype" >
<constructor-arg >
<value><! [cdata[<null>]]></value>
</constructor-arg>
<constructor-arg value= "></constructor-arg>"
</bean>
A reference to a bean that cannot be externally referenced by an internal bean
<bean id= "Person6" class= "Com.lkj.study.beanConfigs.Person" scope= "prototype" >
<property name= "PersonID" ref= "personID1" ></property>
<property name= "Personid.name" value= "Auti" ></property>
</bean>
<bean id= "person7" class= "Com.lkj.study.beanConfigs.Person" scope= "prototype" >
<property name= "PersonID" ref= "personID1" ></property>
<property name= "Personid.name" value= "Auti" ></property>
</bean>
<bean id= "personID1" class= "Com.lkj.study.beanConfigs.PersonID" >
<property name= "name" value= "Baoma" ></property>
<property name= "Price" value= "120000" ></property>
</bean>
<bean id= "car1" class= "Com.lkj.study.beanConfigs.Car" >
<property name= "name" value= "Baoma" ></property>
<property name= "Price" value= "120000" ></property>
</bean>
<bean id= "Car2" class= "Com.lkj.study.beanConfigs.Car" >
<property name= "name" value= "Baoma" ></property>
<property name= "Price" value= "120000" ></property>
</bean>
<bean id= "Person8" class= "Com.lkj.study.beanConfigs.Person" scope= "prototype" >
<property name= "Cars" >
<list>
<ref bean= "Car1"/>
<ref bean= "Car2"/>
</list>
</property>
</bean>
<bean id= "Person9" class= "Com.lkj.study.beanConfigs.Person" scope= "prototype" >
<property name= "Cars" ref= "cars1" >
</property>
</bean>
<util:list id= "Cars1" >
<ref bean= "Car1"/>
<ref bean= "Car1"/>
<ref bean= "Car2"/>
</util:list>
The XML configuration of Spring learning article 02-bean