Results 1 to 3 of 3

Thread: autowiring ServiceListFactoryBean

  1. #1

    Default autowiring ServiceListFactoryBean

    Hi

    I have a ServiceListFactoryBean which creates a list of service implementations:

    Code:
    <bean id="services"
          class="org.springframework.beans...ServiceListFactoryBean"
          p:serviceType="ServiceInterface"/>
    I can access the services using the applicationContext without a problem:

    Code:
    final List services = ctx.getBean("services", List.class));
    I can also use trad constructor-arg injection successfully:

    Code:
    <bean id="aClass" class="AClass">
        <constructor-arg ref="services"/>
    </bean>
    But if I try to autowire the dependency

    Code:
    @Autowired @Qualifier("services") private List services;
    Then I get a BeanCreationException caused by

    Code:
    FatalBeanException: No element type declared for collection [java.util.List]
    I am using Spring 3.0.

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Try using generics to indicate what type exactly you want injected into your list:
    Code:
    @Autowired @Qualifier("services") private List<ServiceInterface> services;
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3

    Default

    I tried that and I got

    Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No matching bean of type [...ServiceInterface] found for dependency [collection of ...ServiceInterface]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Aut owired(required=true), @org.springframework.beans.factory.annotation.Qual ifier(value=services)}

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •