tags:

views:

438

answers:

2

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

<bean id="services"
      class="org.springframework.beans...ServiceListFactoryBean"
      p:serviceType="ServiceInterface"/>

I can access the services using the applicationContext without a problem:

    final List services = ctx.getBean("services", List.class));

I can also use trad constructor-arg injection successfully:

<bean id="aClass" class="AClass">
    <constructor-arg ref="services"/>
</bean>

But if I try to autowire the dependency

@Autowired @Qualifier("services") private List services;

Then I get a BeanCreationException caused by

FatalBeanException: No element type declared for collection [java.util.List]

I am using Spring 3.0.

+2  A: 

It turns out that the answer is ...

@Resource(name="services") private List services;
Paul McKenzie
This will indeed work, because now it is getting autowired by name, instead of by type. That was the case previously. May be you knocked the problem off this time. But you must understand why. So, please ponder over the answer provided. Cheers.
Adeel Ansari
Vinegar -- There are only two beans in the whole project (so far) and regardless of using @Qualifiers or not, or explicitly seting default-autowire to byType or byName, @Autowiring doesn't work for this ServiceListFactoryBean.
Paul McKenzie
+2  A: 

The exception message is from DefaultListableBeanFactory, and it's complining that it can't autowire your field because the List has no generic type (see DefaultListableBeanFactory line 716).

Try adding a generic signature to your field, e.h.

@Autowired @Qualifier("services") private List<Service> services;
skaffman
Yes, you nailed it down. +1
Adeel Ansari
Nope, this doesn't work I'm afraid. Explicitly set autowire to byType and get: No matching bean of type [ServiceInterface] found for dependency [collection of ServiceInterface]
Paul McKenzie