Spring @ Equipped with 2 beans of the same type

I have the following defined.

@Autowired
DaoType1<object1> someDao;

@Autowired
DaoType1<object1> someListDao;

and in my bean definitions i have two beans of the same type

<bean id="someDao" class="com.example.DaoType1" />
<bean id="someListDao" class="com.example.DaoType1" />

The second bean is imported from another XML file, if that matters. They also have different properties. Why spring does not throw an error since 2 beans of the same type are defined. Does this use variable names since they match bean identifiers. The tao are different and the functionality works as expected if I used @Qualifiers for two different beans.

Here is a shorter version. I left the other beans, as I do not mean.

applicationContext.xml

<import resource="classpath:dm-services-crud.xml"/>
<bean id="ruleListCrudService" class="com.idna.dm.service.crud.impl.RuleCrudServiceImpl"> 
    <property name="crudDao" ref="ruleListCrudDao" />
</bean>

de services crud.xml

    <bean id="ruleCrudService" class="com.idna.dm.service.crud.impl.RuleCrudServiceImpl">
        <property name="crudDao" ref="ruleCrudDao" />
        <property name="ruleNetworkOfNodesCrudService" ref="ruleNetworkOfNodesCrudService" />
        <property name="elementMappingsCrudService" ref="elementMappingsCrudService" />
        <property name="ruleCrudDao" ref="newRuleCrudDao"/>
   </bean>

default-autowire is generally absent in any of my xml files.

+3
source share
2

, -, . :

byName

. Spring bean , , . , bean autowire master ( setMaster (..)), Spring bean master, .

, , default-autowire="byName" applicationContext.xml.

. ( ) beans

  • @Qualifier ( )
  • @Resource, @Autowired ( )
+8

@Autowired , "autowire by type" bean xml.

... . , xml.

+1

Source: https://habr.com/ru/post/1769374/