I have this super class:
@Component
public class DAOBase {
}
this other one class extends DAOBase
@Component
public class VoceDAO extends DAOBase{
}
When I AutoWired
the class DAOBase this way
@Service
public class TransactionService {
@Autowired
private DAOBase dAOBase;
}
I get this error:
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.jeansedizioni.dao.DAOBase] is defined: expected single matching bean but found 2: DAOBase,voceDAO
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:865)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 37 more
Reading some posts I found this solution:
@Component("DAOBaseBeanName")
public class DAOBase {
}
I want to be sure I perfectly understood the solution.
With @Component("DAOBaseBeanName")
I give the class DAOBase the specific name "DAOBaseBeanName", with which the application can identify the class DAOBase, in order not to mix it up with other classes that extend DAOBase. Is it right?
Thank you.