**我得到以下错误,即使我已经下了@autowired .请有人让我知道为什么这个问题发生的蚂蚁构建与spring配置utor。2012-07-08 10:18:09 . 856警告org.springframework.context.support。ClassPathXmlApplicationContext -在context初始化过程中遇到异常
- 取消刷新尝试:创建名称为"delegateProcessor"的bean时出错:通过字段'headerProcessor'表示不满意的依赖;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有找到用于依赖的合格bean[org.springframework.batch.item.ItemProcessor<com.abc.proj.model.FileHeader,com.abc.proj.model.FileHeader>):预计至少有1个bean符合自动候选资格。依赖注释:{@org.springframework.beans.factory.annotation.Autowired(required=true),@org.springframework.beans.factory.annotation.Qualifier(值= headerProcessor)}线程"main"中的异常org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为"delegateProcessor"的bean时出错:表示不满意的依赖项通过字段'headerProcessor';嵌套异常是org.springframework.beans.factory。NoSuchBeanDefinitionException:没有找到用于依赖的合格bean[org.springframework.batch.item.ItemProcessor<com.abc.proj.model.FileHeader,.>]:期望至少有1个bean符合自动装配的候选人。依赖项的注释:{@org.springframework.beans.factory.annotation.Autowired(要求= true),@org.springframework.beans.factory.annotation.Qualifier(值= headerProcessor)}
@Component
public class DelegateProcessor implements ItemProcessor<Object, Object>, InitializingBean {
@Autowired
@Qualifier("headerProcessor")
private ItemProcessor<FileHeader, FileHeader> headerProcessor;
@Autowired
@Qualifier("detailProcessor")
private ItemProcessor<FileDetail, FileDetail> detailProcessor;
@Autowired
@Qualifier("trailerProcessor")
private ItemProcessor<FileTrailer, FileTrailer> trailerProcessor;
@Component
public class HeaderProcessor implements ItemProcessor<Object, Object>{
@Autowired
private HeaderValidatorDao headerValidatorDao ;**
使用配置类,您可以手动初始化bean,特别是当它们需要自定义名称时。
@Configuration
public class MyCustomConfiguration {
@Bean(name ="headerProcessor")
public ItemProcessor<FileHeader, FileHeader> headerProcessorBean() {
ItemProcessor<FileHeader, FileHeader> myBean = new HeaderProcessor<>();
//Do whaterever you need to initilize your bean
return myBean;
}
@Bean(name ="detailProcessor")
public ItemProcessor<FileDetail, FileDetail> detailProcessorBean() {
ItemProcessor<FileDetail, FileDetail> myBean = new ItemProcessor<>();
//Do whaterever you need to initilize your bean
return myBean;
}
}
通过这种方式,这些bean将可用于自动装配。