Reputation: 85
I have declared a form object as proxy scoped and maintaining in session. Whenever I am Autowiring the form objects, the code is perfectly working. If I want to access the form object in war layer in a normal POJO class, then it is failing as I am not Autowiring in normal Java class (non Spring). Code snippet...
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "session")
class FormA{
}
In Spring controller, I am able to retrieve FormA in below SpringController
@Controller
Class ControllerB{
@Autowired
FormA formA;
}
But my requirement is to access the FormA in plain Servlet (Non Spring class, servlet 2.4 implementation). How do I retrieve the instance of FormA in Servlet?
Have added below listener entry in web.xml, but it returns new formA but not the original formA object which is in session.
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
Upvotes: 1
Views: 292
Reputation: 632
If request, session and global session scoped beans are injected in Singleton or prototype scoped beans, Spring will inject a generated proxy as dependency.
When target object for proxy is populated, In case of request scope, It will be stored as threadlocal object and for session scope it will be stored in session.When call is made on proxy,it will delegates calls to threadlocal/session scoped target object.
In your case, If FormA object has been populated and proxy has been injected to controller, then you should be able to use this proxy in that request to access FormA object , provided it is in single thread/session.
Upvotes: 2