我有以下Spring组件:
@Component(LogicQualifiedBeanNames.PRODUCT_EVENTS_FLOW_PROCESSOR)
public class ProductEventsFlowProcessor extends AbstractFlowProcessor {
private List<ProductEventDetector> productEventDetectors;
private BesRequestFactory besRequestFactory;
private BesAccessor besAccessor;
@Autowired
public ProductEventsFlowProcessor(ItemsClassifier<WriteProductItem> itemsClassifier,
@Qualifier(LogicQualifiedBeanNames.PRODUCT_EVENTS_DETECTORS) List<ProductEventDetector> productEventDetectors,
BesRequestFactory requestFactory, BesAccessor besAccessor) {
super(itemsClassifier);
this.productEventDetectors = productEventDetectors;
this.besRequestFactory = requestFactory;
this.besAccessor = besAccessor;
}
以下配置类:
@Configuration
public class FlowConfiguration {
private ProductEventDetector deleteProductEventDetector = new DeleteProductEventDetector();
@Bean(name = LogicQualifiedBeanNames.PRODUCT_EVENTS_DETECTORS)
public List<ProductEventDetector> getProductEventDetectors() {
List<ProductEventDetector> productEventDetectors = Lists.newArrayList(deleteProductEventDetector);
return productEventDetectors;
}
}
以下上下文配置文件:
<beans:beans>
<import resource="classpath:core-module-context.xml" />
<context:component-scan base-package="com.stackoverflow.logic" />
<aop:aspectj-autoproxy />
</beans:beans>
当我测试我的应用程序时,收到以下消息:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.stackoverflow.logic.events.ProductEventDetector] found for dependency [collection of com.stackoverflow.logic.events.ProductEventDetector]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=productEventDetectors)}
我已经尝试使用DependsOn
注释,但这没有帮助。
答案 0 :(得分:1)
我发现了问题。
问题是创建了MediaStore
类型的bean。出于某种原因,Spring并不喜欢这样。
该问题有两种解决方案:
List
ArrayList
注释代替@Resource
解决了这个问题,但我仍然不知道为什么Spring拒绝创建类型为@Autowired
的bean。对此有何解释?