简体   繁体   English

休眠弹簧连接无法自动接线

[英]Hibernate Spring connection Could not autowire

I'm trying to do some crud operation on a OracleDB with Hibernate and Spring. 我正在尝试使用Hibernate和Spring在OracleDB上执行一些操作。 I generated the class with HibernateTools. 我使用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". 所有这些都在一个名为“ dataLayer”的项目中。 From an other project I tested it with Junit but I have all the time this kind of error 在另一个项目中,我使用Junit进行了测试,但我一直都遇到这种错误

nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field 嵌套的异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段

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. 由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有找到类型为[it.bnl.btre.orchass.busin.dao.AssegniDao]的匹配bean以获得依赖关系:期望至少有1个有资格作为此依赖项的自动装配候选的bean 。 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) 依赖项注释:org.springframework.beans.factory.support上的{@ org.springframework.beans.factory.annotation.Autowired(required = true),@ org.springframework.beans.factory.annotation.Qualifier(value = AssegniDao)} org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:817)处的org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory)的。 :731)在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: 用以下方式命名bean:

@Repository("AssegnoDao")
public class AssegnoDaoImpl extends AbstractAutowiredDao implements AssegniDao { 

}

Then, when you use @Autowire , don't forget to specity the name of the bean: 然后,当您使用@Autowire ,不要忘记指定bean的名称:

@Autowired
@Qualifier("AssegniDao")
private AssegniDao assegniDao;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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