AutoWire and AutoWire)
Select an Assembly policy based on autowire Configuration
ByName: select the bean with the same name as the property name for assembly;
ByType is selected based on the type. If the corresponding type matches multiple beans, an error is returned, as shown in the following Configuration:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://www.springframework.org/schema/beans 5 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 6 7 <bean name="userDAO1" class="com.bjsxt.dao.impl.UserDAOImpl"> 8 <property name="daoId" value="1"></property> 9 </bean>10 11 <bean name="userDAO2" class="com.bjsxt.dao.impl.UserDAOImpl">12 <property name="daoId" value="2"></property>13 </bean>14 15 <bean id="userService" class="com.bjsxt.service.UserService" scope="singleton" autowire="byType">16 <!-- <property name="userDAO">17 <ref bean="userDAO1"/>18 </property> -->19 </bean>20 21 </beans>
Error:
You can also configure the Assembly policy of the entire configuration file under the beans label. The values in the configuration file are the same.
Code link: http://pan.baidu.com/s/1slPPUzz password: 1d9e
Jar package link: http://pan.baidu.com/s/1pKAKAQB password: fjc3