I am creating beans by calling the method getAction in a loop.
...
ArrayList<Action> actions = new ArrayList<Action>();
for(int i=0; i<actionClasses.length; i++)
{
actions.add(getAction((Class<? extends Action>) Class.forName(actionClasses[i])));
}
...
@Bean
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public Action getAction(Class<? extends Action> clazz) throws Exception
{
return clazz.newInstance();
}
The issue is that only the first bean created is autowired. The rest of the beans created have null values for fields supposed to be autowired. However, things started working when the newInstance was replaced with createBean as below.
...
for(int i=0; i<actionClasses.length; i++)
{
actions.add(context.getAutowireCapableBeanFactory().createBean((Class<? extends Action>) Class.forName(actionClasses[i])));
}
...
Can anybody explain why this is happening?
Note: all the action classes are different.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…