Is it possible from Spring to inject the result of calling a method on a ref bean?
I\'m trying to refactor some cut/pasted code from two separate projects into a co
Or in Spring 2.x, by using a BeanPostProcessor
Typically, bean post processors are used for checking the validity of bean properties or altering bean properties (what you want to) according to particular criteria.
public class MyClientBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware {
private ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if((bean instanceof MyClient)) && (beanName.equals("MyClient"))) {
Myregistry registryService = (Myregistry) applicationContext.getBean("registryService");
((MyClient) bean).setEndPoint(registryService.getEndPoint("bar"));
}
return bean;
}
}
And register your BeanPostProcessor