|
|
Default value of singleton in the SimpleStepFactoryBean.java
Hello,
As I see, the default value of singleton in the SimpleStepFactoryBean.java is quot;truequot; from the Spring Batch 2.0.3.Realse version.
Code:
private boolean singleton = true;
But, I can see following note in javadoc of FactoryBean(
sprin...ctoryBean.html)
NOTE:If a FactoryBean indicates to hold a singleton object, the object returned from getObject() might get cached by the owning BeanFactory. Hence, do not return true unless the FactoryBean always exposes the same reference.
The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.
In the quot;getObjectquot; method of SimpleStepFactoryBean, it creates new objects to return whenever it is executed as following.Code:
public final Object getObject() throws Exception {
TaskletStep step = new TaskletStep(getName());
applyConfiguration(step);
step.afterPropertiesSet();
return step;
}
public Classlt;TaskletStepgt; getObjectType() {
return TaskletStep.class;
}
Hence, in my opinion a default value of singleton should be quot;falsequot;.
If I have wrong infomation, please let me know what is my error.
Thank you.
The ApplicationContext is handling all the logic, the getObject is only called once, due to the fact that it is defined as a singleton (the method isSingleton returns true) this indicates the container that it needs/must call the getObject method just once. |
|