2
我在我的war文件的lib文件夹下放了一个jar文件。在jar里面,我有一些使用@Autowired fileds的类。罐子里面,ApplicationContext中的XML我已经给注入自动装配的依赖关系在jar文件中失败
<context:component-scan base-package="com.main.java.mypath" />
代码:
package com.main.java.mypath.client;
@Component
public class ServiceProvider {
@Autowired
private StoreField storeField;
package com.main.java.mypath.data;
public interface StoreField {
}
错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceProvider': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.main.java.mypath.data.StoreField com.main.java.mypath.client.ServiceProvider.storeField; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.main.java.mypath.data.StoreField] 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)}
你有*注射类型'StoreField'的候选人吗? – luk2302
您在StoreField实施中使用了哪些软件包? – dvelopp
'StoreField'是根据定义的接口。你有没有在任何课程上实现这个接口?接口不能自动布线。你需要一个自动装配类。 –