I am new to the spring and got stuck on some point as explained below -
I have a class color with two different implementation name as Red and Blue and I would like to inject both into the List of color using @inject
.
Below is my ApplicationConfiguration class
package org.arpit.java2blog.config;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.arpit.java2blog.model.Country;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import(CountryConfig.class)
public class ApplicationConfiguration {
@Inject
private List<Color> colorList;
@Bean
public List<Color> colorList() {
System.out.println("Second");
List<Color> aList = new ArrayList<Color>();
aList.add(new Blue());
return aList;
}
}
but getting exception as
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.List org.arpit.java2blog.config.ApplicationConfiguration.colorList; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.arpit.java2blog.config.Color] found for dependency [collection of org.arpit.java2blog.config.Color]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}