Five methods of Spring auto-wire: 1: no the default method is not to perform automatic assembly, by manually setting the ref attribute for assembly bean2: byName automatic assembly by parameter name, if the name of a bean is the same as the property of another bean, it is automatically assembled. 3: byType is automatically assembled by the Data Type of the parameter. If the data type of a bean is compatible with the Data Type of the property of another bean, it is automatically assembled. 4: parameters in the construct constructor are automatically assembled in byType format. 5: If autodetect has a default constructor, it is automatically assembled in construct mode. Otherwise, it is automatically assembled in byType mode. For spring2.5, spring3.0 fails the test and is probably discarded. I. auto-wire: no (default) First, define the class required for the test: [java] package com. myapp. core. autowire; public class Book {public String toString () {return "I'm a book, read me ...... ";}} [java] package com. myapp. core. autowire; public class Person {private Book book; public Person (Book book) {this. book = book;} public void setBook (Book book) {this. book = book;} public String toString () {return "I'm a person I want to read A book "+ book;} public Person () {}} default configuration: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <! -- More bean definitions for data access objects go here --> <bean id = "person" class = "com. myapp. core. autowire. person "> <property name =" book "ref =" book "/> </bean> <bean id =" book "class =" com. myapp. core. autowire. book "> </bean> </beans>: [java] package com. myapp. core. autowire; import org. springframework. context. applicationContext; import org. springframework. context. support. classPathXmlApplicationC Ontext; public class MainTest {public static void main (String [] args) {ApplicationContext context = new ClassPathXmlApplicationContext ("resource/autowire. xml "); Person person = (Person) context. getBean ("person"); System. out. println (person. toString () ;}} Test Result: I'm a person I want to read a book I'm a book, read me ...... ii. Automatic Assembly by byName: modify the configuration file as follows: In this example, the bean is automatically assembled by its attribute name, because the property book of this person bean and the id in the configuration file Because the book name is the same, Spring will automatically assemble it through setBook. [Html] <! -- ByName --> <bean id = "person" class = "com. myapp. core. autowire. person "autowire =" byName "> </bean> <bean id =" book "class =" com. myapp. core. autowire. book "> </bean> run the test class: the above test results are still obtained. 3. Automatic Assembly by byType: In this example, automatic assembly is performed by the type of bean attribute name; because the type of the person bean property book is the same as that of the book id in the configuration file ,. Therefore, spring uses setBook for automatic assembly. Modify the configuration file as follows: [html] <! -- ByType --> <bean id = "person" class = "com. myapp. core. autowire. person "autowire =" byType "/> <bean id =" book "class =" com. myapp. core. autowire. book "> </bean> 4: Automatic construct Assembly: automatic assembly is performed by the Data Type of the constructor's parameters. In this example, because the person Constructor's parameters are of the Book type, it is of the same type as the book id in the configuration file. Therefore, spring uses the Person (Book book) constructor to automatically assemble the data. Modify the configuration file as follows: [html] <! -- Construct --> <bean id = "person" class = "com. myapp. core. autowire. person "autowire =" constructor "/> <bean id =" book "class =" com. myapp. core. autowire. book "> </bean> 5: automatic assembly through autodetect: the xml configured in Spring 3.0 cannot be used for autodetect. spring3.0 should have removed this function and use spring2.5 to pass the test smoothly, first, use the construct automatic assembly form for assembly. If no construct is available, use the byType form for automatic assembly. [Html] <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> [html] <bean id = "person" class = "com. myapp. core. autowire. person "autowire =" autodetect "/> <bean id =" book "class =" com. myapp. core. autowire. book "> </bean> </Beans> Test Result: I'm a person I want to read a book I'm a book, read me ...... conclusion: automatic assembly is difficult to see the reference relationship between beans, which increases the reading complexity. Generally, manual configuration is adopted by default or annotation is used for configuration. Additional: the overall configuration is released step by step for testing: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <! -- <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> --> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://www.spring Framework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd "> <! -- More bean definitions for data access objects go here --> <! -- No --> <! -- <Bean id = "person" class = "com. myapp. core. autowire. person "> <property name =" book "ref =" book "/> </bean> --> <! -- ByName --> <! -- <Bean id = "person" class = "com. myapp. core. autowire. Person" autowire = "byName"> </bean> --> <! -- ByType --> <! -- <Bean id = "person" class = "com. myapp. core. autowire. Person" autowire = "byType"/> --> <! -- Construct --> <! -- <Bean id = "person" class = "com. myapp. core. autowire. Person" autowire = "constructor"/> --> <! -- Autodetect --> <bean id = "person" class = "com. myapp. core. autowire. person "autowire =" autodetect "/> <bean id =" book "class =" com. myapp. core. autowire. book "> </bean> </beans>