Reputation: 121
I'm trying to do some crud operation on a OracleDB with Hibernate and Spring. I generated the class with HibernateTools. I create an Interface like this:
public interface AssegniDao {
}
and an implementation like this
@Repository
@Qualifier("AssegniDao")
public class AssegnoDaoImpl extends AbstractAutowiredDao implements AssegniDao {
}
This is all in a project called "dataLayer". From an other project I tested it with Junit but I have all the time this kind of error
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field
How can I solve this?
Full stack trace
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [it.bnl.btre.orchass.busin.dao.AssegniDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=AssegniDao)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:948) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:817) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:731) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:485)
Upvotes: 0
Views: 327
Reputation: 44506
Don't forget to scan the packages first:
<context:component-scan base-package="the.path.to.your.package.with.controller" />
Name the bean with:
@Repository("AssegnoDao")
public class AssegnoDaoImpl extends AbstractAutowiredDao implements AssegniDao {
}
Then, when you use @Autowire
, don't forget to specity the name of the bean:
@Autowired
@Qualifier("AssegniDao")
private AssegniDao assegniDao;
Upvotes: 1