我使用maven添加jar与bean。 我想在上下文文件中自动装配它们......
<?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>
问题:当我运行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)
尽管所有maven依赖项都已导入并存在。 更多在Idea中,在LinuxOS环境下工作,问题只出在eclipse,Windows操作系统中。
答案 0 :(得分:0)
如果Spring没有找到任何自动装配的bean,就会抛出这种异常。这可能是因为您正在自动装配接口,但没有该接口的实际实现。检查您的StatisticsService是否属于这种情况。
答案 1 :(得分:0)
我有时候和你有同样的问题。删除.m2中的本地com.ac. *包文件,然后再次下载。