Has anyone tried to auto-wire different beans into a Spring-managed bean based on a condition? For e.g. if some condition is met, inject class A, else B? I saw in one of the
I suppose the simpest way:
@Autowired @Lazy protected A a; @Autowired @Lazy protected B b; void do(){ if(...) { // any condition // use a } else { // use b } }
In case you do not declare nessassary bean, Spring throws at runtime NoSuchBeanDefinitionException
NoSuchBeanDefinitionException