Let's assume I have an annotated bean property setter like this:
public class Foo {
...
@Autowired
public void setBar(Bar bar) {
...
}
The Springframework will lookup the matching Bar property as usual. However, I'd like to intercept the default bean resolving process and add a little bit of "magic" myself. I'd like to introduce a resolver like this:
public interface SomeResolverInterface<T> {
public T resolve(Class<T> beanClass);
}
public class BarResolver implements SomeResolverInterface<Bar> {
@Override
public Bar resolve(Class<Bar> beanClass) {
if(someCondition) {
return someBean;
} else {
return anotherBean;
}
}
...
I know I could alway introduce some kind of wrapper bean and move the resolving logic into this but I'd prefer a more generic way using a resolver like described above to make Foo completely independent of the resolving logic.
Is there a way within the Springframework to achieve something like this?