In spring, you can use automatic assembly by construction, which is actually automatically assembled by the parameter type of the constructor. This means that if the data type of a bean is the same as the data type of the constructor parameters of other beans, it will be automatically assembled.
Package Auto_constructor; /** */Publicclass student {public String getName () { return name; } Public void setName (String name) { this. Name = name; } Private String name;}
Package Auto_constructor; /** */Publicclass school {public School (student St) { this. st=St; } Public Student Getst () { return st; } Private student St;}
<!-- Construction method Injection is actually automatically assembled by the parameter type of the constructor-- class= "Auto_constructor.student" > <property name= "name" value= "Cat" ></property> </bean> class= "Auto_ Constructor.school "Autowire=" constructor "></bean>
In spring, "auto-assemble by automatic detection" means that if there is a default constructor (parameter and any data type) The constructor injection is installed, and if no constructor is automatically assembled by type.
<bean id= "Student" class= "auto_constructor.student" > <property name= "name" value= "Cat" ></ property> </bean> <bean id= "School" class= "Auto_constructor.school" autowire= "AutoDetect" ></bean>
--constructor in spring by constructing automatic assembly