Incorrect use of annotation combinations @Autowired and @Qualifier to populate resource through dependency injection.

org.springframework.beans.factory.NoSuchBeanDefinitionException
Javadoc
Exception thrown when a {@code BeanFactory} is asked for a bean instance for which it cannot find a definition. This may point to a non-existing bean, a non-unique bean, or a manually registered singleton instance without an associated bean definition. @author Rod Johnson @author Juergen Hoeller @author Stephane Nicoll @see BeanFactory#getBean(String) @see BeanFactory#getBean(Class) @see NoUniqueBeanDefinitionException
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException
(source)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency
(source)

Typical Exception Messages

  1. No matching 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=myList)}
  2. Failed to load ApplicationContext

Solution

rahsan, 4 months ago

While trying to populate resources like List<String> using @Autowired and @Qualifier is technically allowed, but will result in NoSuchBeanDefinitionException. The solution to the problem is to use @Resource annotation with the bean id as name parameter. For more details check this solution. For information as to how @Autowire and @Qualifier can be used check this

External results for this pattern (2)

  1. Christian Schneidervia camel-users5 months ago
  2. No matching 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=myList)}
    Show stack trace