Simon,
I think you are on the right track. Your confusion seems to stem from the fact that you are confusing two different concepts in the creation of the application context; you are trying to work with BeanDefinitions and instantiated objects at the same time. Your work in the BeanFactoryPostProcessor needs to focus squarely on the BeanDefinitions. You will be manipulating information in the BeanFactory before the actual bean objects get instantiated. That way, when they are finally created, they will have the correct definitions.
When you dig into the BeanFactory, you will be pulling out BeanDefinitions, *not* Steps/Jobs/FactoryBeans or anything else instantiated like that.
Code:
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
PropertyValues prototypePvs = beanFactory.getBeanDefinition("prototypeStepName").getPropertyValues();
for (String beanName : beanFactory.getBeanDefinitionNames()) {
BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
if (isAbstractStep(bd, beanFactory)) {
MutablePropertyValues pvs = (MutablePropertyValues) bd.getPropertyValues();
//
// Here is where you should pull information out of 'prototypePvs'
// and inject into 'pvs'
//
}
}
}
/**
* @param bd
* @param beanFactory
* @return TRUE if the bean represents an AbstractStep (or
* StepParserStepFactoryBean).
*/
private boolean isAbstractStep(BeanDefinition bd, ConfigurableListableBeanFactory beanFactory) {
Class<?> stepClass = getClass(bd, beanFactory);
return StepParserStepFactoryBean.class.isAssignableFrom(stepClass)
|| AbstractStep.class.isAssignableFrom(stepClass);
}
I actually just implemented something like this two days ago to fix a bug for the 2.0.1 release. Check out https://fisheye.springsource.org/bro...Processor.java to get an idea of what you may need.
As a side note, the '&' that appears in front of the FactoryBean name is automatically put there by Spring. For example, the StepParserStepFactoryBean is used to create a Step. You configure the FactoryBean in your XML, but you need the Step to be in the ApplicationContext as well. If the 'id' of the FactoryBean is "step1", then we want the Step's name to be "step1". You can see that this could cause a conflict since you have two different beans with the same name. So Spring changes the FactoryBean's id to "&step1" to differentiate it from the Step itself.