简体   繁体   English

在jar的maven依赖项中找不到要自动连线的Bean,

[英]Cannot find bean to autowire which is in maven dependencies in jar,

I add jar with bean using maven. 我使用Maven将jar与bean一起添加。 Than I want to autowire them in context file... 比我想将它们自动关联到上下文文件中...

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="statisticsService" class="com.ac.kpi.AcStatisticsService">
        <constructor-arg name="dataService" ref="acDataService"/>
    </bean>

</beans>

Problem: when I run tomcat I get Error: 问题:运行tomcat时出现错误:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.ac.kpi.StatisticsService] 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)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1326)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1072)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:967)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)

Despite the fact that all maven dependencies are imported and present. 尽管事实上所有maven依赖项都已导入并存在。 MoreOver in Idea, in LinuxOS everyring work, problem is only in eclipse, Windows OS. 此外,在Idea中,在LinuxOS的所有工作中,问题仅在于Eclipse,Windows OS。

This kind of exception is thrown if Spring doesn't find any bean to autowire. 如果Spring找不到要自动装配的bean,则抛出这种异常。 This may be due to the fact that you are autowiring an interface but there is no actual implementation of that interface. 这可能是由于您正在自动装配接口而没有该接口的实际实现。 Check if this is the case of your StatisticsService. 检查您的StatisticsService是否属于这种情况。

I have same problem with you sometimes. 有时候我也有同样的问题。 Delete the local com.ac.* package file in .m2, then download it again. 删除.m2中的本地com.ac. *程序包文件,然后再次下载。

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

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