AutoWire and AutoWire)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.