简体   繁体   中英

Hibernate Spring connection Could not autowire

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?

Edit

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)

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM