When you component-scan a class with a @Component
, @Repository
, @Service
, @Configuration
, etc. annotation, Spring implicitly creates a bean for it. It also creates a bean for it when you explicitly declare one, ie. this
<bean id = "Tblusers_DAOImpl" class="DAO.Tblusers_DAOImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id = "TblUserManager_DAOImpl" class="DAO.TblUserManager_DAOImpl">
So currently, you have two beans for TblUserManager_DAOImpl
and Tblusers_DAOImpl
. Spring does not know which one to inject in fields like
@Autowired
private TblUserManager_DAO user;
because there are two candidates. Either remove the <bean>
declaration or qualify the injection target with something like @Qualified
to select the appropriate bean.
Here's the documentation. Go through it to understand the whole process of component scanning.
As JB Nizet stated below, you should only annotate the actual implementation class with @Component
or any of its specialization. Think of it semantically, an interface is not a component, no bean can be created for an interface. Only an actual class, an implementation of an interface, can be a component.