Claudio D'Angelo opened SPR-12180 and commented
I have a controller class with a field List<String> autowired:
@Autowired()
@Qualifier("publicViews")
private List<String> publicViews;
In my configuration I've wrote:
<util:list id="publicViews" value-type="java.lang.String">
<value >gestione</value>
<value >inserimento</value>
<value >dettaglio</value>
</util:list>
<context:component-scan
base-package="it.lispa.sire.tributi.aper_pdt.au.cicloquad.controllers" />
When the application start spring throw an error:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.lang.String] found for dependency [collection of java.lang.String]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=publicViews)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:997)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:825)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:779)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:490)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
....
In the DefaultListableBeanFactory the search for autowire candidate get the collection type and use this type to search the candidate:
else if (Collection.class.isAssignableFrom(type) && type.isInterface()) {
Class<?> elementType = descriptor.getCollectionType();
if (elementType == null) {
if (descriptor.isRequired()) {
throw new FatalBeanException("No element type declared for collection [" + type.getName() + "]");
}
return null;
}
Map<String, Object> matchingBeans = findAutowireCandidates(beanName, elementType, descriptor);
I think that the system must search candidate for the type variable and not for elementType. In my issue the elementType is String not java.util.List.
Affects: 3.2.11
Issue Links:
0 votes, 8 watchers
Claudio D'Angelo opened SPR-12180 and commented
I have a controller class with a field
List<String>autowired:In my configuration I've wrote:
When the application start spring throw an error:
In the
DefaultListableBeanFactorythe search for autowire candidate get the collection type and use this type to search the candidate:I think that the system must search candidate for the
typevariable and not forelementType. In my issue theelementTypeisStringnotjava.util.List.Affects: 3.2.11
Issue Links:
@Produces(for Array/Map/Collection inject) ("is duplicated by")@Autowired-likeself injection@Named0 votes, 8 watchers