Hi I have created a factory, with the help of some guidance from @DruidKuma from the link : Implement a simple factory pattern with Spring 3 annotations
I created the factory as follows:
@Component
public class ValidatorFactory {
@Autowired
private List<Validator> validators;
private static final Map<String, Validator> validatorMap = new ConcurrentHashMap<>();
@PostConstruct
public void setValidatorMap() {
for (Validator validator : validators) {
validatorMap.putIfAbsent(validator.getCountry().name(), validator);
}
}
public Validator getValidator(Value v) {
return validatorMap.get(v.name());
}
}
But when I am trying to start the application I am getting this error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field validators in com.abc.factory.ValidatorFactory required a bean of type 'java.util.List' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'java.util.List' in your configuration.
What I understood from the link which helped me was that spring should create the bean automatically. Can someone please help me with this?