Spring @Autowire Bean 构造函数 NoSuchBeanDefinitionException Hibernate 服务
当我尝试自动装配 Bean 构造函数时,出现以下错误:
原因:org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到依赖项的 [dimensionmanagement.service.DimensionService] 类型的匹配 bean:预计至少有 1 个有资格作为此依赖项的自动装配候选者的 bean。依赖注释:{} 在org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920) 在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789) 在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703) 在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) 在 org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) ... 89 更多
我已经定义了Dimensionmanagement.service.DimensionService,如下所示:
@Service @Transactional public class DimensionService implements Serializable {
在我的applicationContext.xml中:
<context:annotation-config/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<context:component-scan base-package="dimensionmanagement" />
如果还有其他问题,请询问! 谢谢乔纳斯
I have the following error, when I try to Autowire my Bean constructor:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [dimensionmanagement.service.DimensionService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
... 89 more
I have defined the dimensionmanagement.service.DimensionService like that:
@Service @Transactional public class DimensionService implements Serializable {
in my applicationContext.xml :
<context:annotation-config/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<context:component-scan base-package="dimensionmanagement" />
if any more questions please ask!
Thanks Jonas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该是自动装配接口而不是类。
DimensionService
应该是一个接口。通过实现DimensionService
创建类DimensionServiceImpl
如果您想继续使用 class,请阅读 这里介绍如何做到这一点。
You should be autowiring interface and not a class.
DimensionService
should be an interface. Create a classDimensionServiceImpl
by implementingDimensionService
If you want continue using class read here on how to do it.
你需要
you need