2

I have the following Spring component:

@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;
}

And the following configuration class:

@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;
    }
}

And the following context configuration file:

<beans:beans>
    <import resource="classpath:core-module-context.xml" />

<context:component-scan base-package="com.stackoverflow.logic" />
<aop:aspectj-autoproxy />   

</beans:beans>

When I test my application, I get the following message:

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)}

I already tried to use DependsOn annotation, but that doesn't help.

Bohuslav Burghardt
  • 33,626
  • 7
  • 114
  • 109
Amir Kost
  • 2,148
  • 1
  • 16
  • 30
  • similar question : http://stackoverflow.com/questions/33167789/beans-property-is-not-setting-from-utillist-object/33170175#33170175 – Lovababu Padala Oct 28 '15 at 14:03

1 Answers1

2

I found the problem. The problem was creating a bean of type List. For some reason, Spring doesn't like that. There are 2 solutions to the problem:

  1. Use a concrete class like ArrayList
  2. Use @Resource annotation instead of @Autowired

That solved the problem, but I still don't know why Spring refuses to create a bean of type List. Any explanation for that?

Amir Kost
  • 2,148
  • 1
  • 16
  • 30