Question related to protype scoped beans
Hello ,
I have a question regarding protype scope.
Background:
I am using spring 3.0.I am using spring webservice module to create webservices and spring jdbc for data access.
The dao methods are Autowired to webservice.
Spring webservice uses a helper class which has dao methods autowired to it. Earlier this class was assumed to be singleton so it was autowired to service everything worked fine.
Due to design change now this class need to maintain the state . I.e. remember values between method call. So we need to create a new instance of helper class everytime service is called. To resolve this I changed application context.xml and added bean with prototype scope like this :
Code:
<bean id="abcHelper" class="com.abc.AbcHelper" scope="prototype">
</bean>
I am getting the bean from application context .
My bean class look like this :
Code:
package com.abc;
public class AbcHelper {
@Autowired
private AncDAO abcDAO;
public void initialize(String xyz){
//initialization stuff
}
public String getXXX(){
// SOME MORE STUFF
}
}
I am calling this from spring webserivce as below :
Code:
AbcHelper abcHelper = (AbcHelper) context.getBean("abcHelper");
abcHelper.initialize(service.get1());
//some more stuff
abcHelper.getXXX();
Question : Is this approach correct. In general creating prototype scoped beans is considered a bad idea . If this approach is not correct what else can be done in my case. I need to call the helper class which needs dataaccess objects injected by spring container. And this also needs to maintain the state between invocations.
This webservice is gonna be a heavily hit webservice with millions of hit each day. Would prototype scope will make it slow ?