java - Hibernate Spring 连接无法 Autowiring

标签 java spring hibernate

我正在尝试使用 Hibernate 和 Spring 在 OracleDB 上执行一些增删改查操作。 我用 HibernateTools 生成了该类。我创建一个这样的界面:

public interface AssegniDao {

}

和这样的实现

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

}

这一切都在一个名为“dataLayer”的项目中。在另一个项目中,我使用 Junit 对其进行了测试,但我一直遇到这种错误

nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field

我该如何解决这个问题?

编辑

完整堆栈跟踪

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)

最佳答案

不要忘记先扫描包裹:

<context:component-scan base-package="the.path.to.your.package.with.controller" />

将 Bean 命名为:

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

}

然后,当您使用@Autowire时,不要忘记指定bean的名称:

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

关于java - Hibernate Spring 连接无法 Autowiring ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44456339/

相关文章:

java - Jersey:将 Spring 组件注入(inject) ContainerRequestFilter

hibernate - 非法状态异常 : Error occurred while storing entity <entity> An entity copy <entity> was already assigned to a different entity <entity_copy>

mysql - org.hibernate.HibernateException : Missing column: auth_password in Spring Boot application

java - jpa (Hibernate) 中具有重复行的结果集

java - (IntelliJ GUI Designer) 将组件添加到 JPanel 时出现运行时 NullPointerException

amazon-web-services - curl : (35) Cannot communicate securely with peer: no common encryption algorithm(s)

java - Java 中的文本文件读取和打印

java - 在这种情况下,字符串构造函数 - String(String original) 中的 'size > originalValue.length' 会是 0x104567910 吗?

java - 将 java.util.Map 从 jsp 传递到 servlet

java - cvc-complex-type.2.4.c : The matching wildcard is strict, 但找不到元素 'mvc:annotation-driven' 的声明