自动装配类型可以用于创建同一bean的多个实例吗?

时间:2019-05-25 09:14:05

标签: spring

在类路径资源[employeeautowiringbytype / EmployeeAutowiringByType.xml]中创建名称为'emp1'的bean时出错:通过bean属性'localadrs1'表达的不满意依赖性::没有定义类型[employeeautowiringbytype.LocalAddress]的合格bean:期望单个匹配的Bean,但发现3:localadrs1,localadrs2,localadrs3;

<?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:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans 
 http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
 http://www.springframework.org/schema/aop 
 http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
 http://www.springframework.org/schema/tx 
 http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

 <bean id="native1" class="employeeautowiringbytype.Native">
        <property name="town" value="Tenkasi"/>
        <property name="city" value="Tirunelveli"/>
        <property name="state" value="Tamil Nadu"/>
    </bean>

    <bean id="localadrs1" class="employeeautowiringbytype.LocalAddress">
        <property name="doorNo" value="45"/>
        <property name="pin" value="600077"/>
        <property name="streetName" value="Bharathiyaar street"/>
        <property name="city" value="Chennai"/>
        <property name="state" value="Tamil Nadu"/>
    </bean>

    <bean id="emp1" class="employeeautowiringbytype.Employee" 
        autowire="byType">
        <property name="id" value="1001"/>
        <property name="name" value="Lakshmi"/>
        <property name="designation" value="Senior Application Developer"/>    
    </bean>


    <bean id="native2" class="employeeautowiringbytype.Native">
        <property name="town" value="Sivakasi"/>
        <property name="city" value="Virudhunagar"/>
        <property name="state" value="Tamil Nadu"/>
    </bean>

    <bean id="localadrs2" class="employeeautowiringbytype.LocalAddress">
        <property name="doorNo" value="37"/>
        <property name="pin" value="600012"/>
        <property name="streetName" value="Arcot street"/>
        <property name="city" value="Chennai"/>
        <property name="state" value="Tamil Nadu"/>
    </bean>

     <bean id="emp2" class="employeeautowiringbytype.Employee" 
         autowire="byType">
        <property name="id" value="2001"/>
        <property name="name" value="Bhavani"/>
        <property name="designation" value="Junior Application Developer"/>    

    </bean>

    <bean id="native3" class="employeeautowiringbytype.Native">
        <property name="town" value="Chidambaram"/>
        <property name="city" value="Cuddalore"/>
        <property name="state" value="Tamil Nadu"/>
    </bean>

    <bean id="localadrs3" class="employeeautowiringbytype.LocalAddress">
        <property name="doorNo" value="23"/>
        <property name="pin" value="600019"/>
        <property name="streetName" value="Manickavasagam street"/>
        <property name="city" value="Chennai"/>
        <property name="state" value="Tamil Nadu"/>
    </bean>

     <bean id="emp3" class="employeeautowiringbytype.Employee" 
         autowire="byType">
        <property name="id" value="3001"/>
        <property name="name" value="Brundhavathi"/>
        <property name="designation" value="Senior Test Engineer"/>    

    </bean>

</beans>

0 个答案:

没有答案