The SPRINGIOC container is the core content of spring.
role: Create objects & handle dependencies on objects.
I. IOC container Creation object:
1. There are several ways to create objects:
1) Call parameterless constructor
2) with parametric constructor
3) factory-created objects
A) factory class, static method Creation object
b) Factory class, non-static method to create objects
2. Application.xml configuration file:
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:context= "Http://www.springframework.org/schema/context" xsi:schemalocation= "Http://www.springframework.org/schema/bea NS Http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/cont Ext http://www.springframework.org/schema/context/spring-context.xsd "> <!--############## #对象创建 ######## #######-<!--1. Default parameterless constructor <bean id= "user1" class= "Mfq.beans.User" ></bean> <!--2. With parametric constructor--<bean id= "user2" class= "Mfq.beans.User" > <constructor-arg index= "0" type= "int" value= "1 XX "></constructor-arg> <constructor-arg index=" 1 "type=" java.lang.String "value=" Jack "></constru Ctor-arg> </bean> <!--defines a string with the value "Jack"; string s = new string ("Jack")--<bean id= "str" class= "java.lang.String" > <constructor-arg value= " Jacks "></constructor-arg> </bean> <bean id=" User3 "class=" Mfq.beans.User "> <constr Uctor-arg index= "0" type= "int" value= "></constructor-arg> <constructor-arg index=" 1 "type=" java.la Ng. String "ref=" str "></constructor-arg> </bean> <!--3. Factory class Create objects-<!--# 3.1 factory class, instance method-<!--first create factory--<bean id= "Factory" class= "Mfq.beans.Objec Tfactory "></bean> <!--Creating a user object, using factory side instance Method--<bean id=" User4 "factory-bean=" factory "fact
Ory-method= "getinstance" ></bean> <!--# 3.2 factory class: Static Method--<!--class specifies the factory type Factory-method must be the "static method"--<bean id= "user" class= "mfq.beans.ObjectFactory" factory-method= "Getstat" inside the factory Icinstance "></bean> </beans>
Second, object dependency relationship
1. How do I assign values to an object's properties in spring? "DI, Dependency Injection"
1) through the constructor function
2) Injecting a value into a property by a set method
3) P name space
4) automatic assembly (understanding)
5) annotations
2, "common" set method injection value
1) Common version set method injection value
<!--DAO Instance--
<bean id= "Userdao" class= "Mfq.test.UserDao" ></bean>
<!--service Instance--
<bean id= "UserService" class= "Mfq.test.UserService" >
<property name= "Userdao" ref= "Userdao" ></property>
</bean>
<!--action Instance-
<bean id= "Useraction" class= "Mfq.test.UserAction" >
<property name= "UserService" ref= "UserService" ></property>
</bean>
2) Variable version set method injection value (internal bean)
<!--############# #内部bean ##############--<bean id= "useraction" class= "mfq.tes
T.useraction "> <property name=" userservice "> <bean class=" Mfq.test.UserService ">
<property name= "Userdao" > <bean class= "Mfq.test.UserDao" ></bean> </property> </bean> </property> </bean>