-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Provide ability to make aop:scoped-proxy prototypes and singletons truely serializable [SPR-2121] #6812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Davide Baroncelli commented Has anything been done in this regard? I think something similar has been built by the wicket-spring project: since wicket serializes the pages, all injected objects would be lost. They have built a proxying mechanism so that the pages actually get a proxy which is able to get the actual bean out of the factory upon deserialization. I believe a "standard Spring" solution to this problem would be great! |
Mike Youngstrom commented It is unfortunate that this has slipped to 3.1. I believe springs inability to address injection into serializable beans is a rather major shortcoming of Spring today. This is compounded with the fact that this is not a problem for several competing frameworks. Most notably: Guice has its "Provider" injection pattern. Spring Webflow itself adds a few new scopes that should be serializable. Any scope that could serialize a bean currently cannot have anything injected into it (except possibly beans of the same scope). That is a huge limitation IMHO. I hope you can reconsider this functionality for Spring 3.0 as this is currently a major spring pain point for my organization. Mike |
Juergen Hoeller commented This is finally making its way into Spring 3.0 now! We are storing a serialization id only for any DefaultListableBeanFactory being serialized, when running within an ApplicationContext... This id is equivalent to the ApplicationContext's id (as configurable via the setId method). This solves a large group of problems: Not only are scoped proxies generally serializable now; the aop:scoped-proxy element gets a proper use for singletons as well, defining a serialization reference for that target singleton. Also, any beans that are BeanFactoryAware can be serializable now as well. In terms of static state cleanup, we register a BeanFactory by id only for an ApplicationContext, and deregister it when the ApplicationContext shuts down. Furthermore, the BeanFactory is registered using a weak reference, for cases where an ApplicationContext instance is simply left to the garbage collector. Juergen |
Mike Youngstrom commented Excellent!!!! I cannot wait to try it out deprecate my custom solution. Mike |
Andreas Petersson commented i just tried this out with spring 3 RC1. unfortunately it does not seem to work out-of the box.
without the aop:scoped proxy config, serialization fails earlier with the following stacktrace: Cannot serialize session attribute KontaktverwaltungBean for session 2CE927F2B35173DA239969DD388F2E77
with aop:scoped-proxy enabled KundenDao proxy starts to serialize itself, but fails in DefaultListableBeanFactory which holds a field autowireCandidateResolver to an instance of QualifierAnnotationAutowireCandidateResolver is it correct that serialization should look that deep into spring? for me it looks like a bug in handling the proxys. Cannot serialize session attribute KundenSucheController for session 44479BC944988DB073B725FE428E6950
|
Andreas Petersson commented the above output was generated with -Dsun.io.serialization.extendedDebugInfo=true |
Andreas Petersson commented i just tried this out with interfaces only + JDK-proxies, with a slightly different output but the same result. settings:
stacktrace:
|
RSKB commented I have a bean declared as below : <bean id="sessionBean" class="com.test.SessionBean" scope="session"> I see following errors written to SystemOut logs. Miscellaneous data: Attribute "org.springframework.web.context.request.ServletRequestAttributes.DESTRUCTION_CALLBACK.scopedTarget" |
RSKB commented I have a bean declared as below : <bean id="sessionBean" class="com.test.SessionBean" scope="session"> I see following errors written to SystemOut logs. Miscellaneous data: Attribute "org.springframework.web.context.request.ServletRequestAttributes.DESTRUCTION_CALLBACK.scopedTarget" |
Chris Beams commented
|
Mike Youngstrom opened SPR-2121 and commented
It would be nice if there were a way to make singleton and prototype scoped-proxies truely serializable where if the proxy is serialized the target is retrieved from a BeanFactory instead of being serialized with the proxy (similar to how request and session scoped-proxies work).
I believe the complexity of this functionality is in the locating of a BeanFactory when it is unserialized. Rather than providing some way for the correct BeanFactory to always magically be found all I'm looking for is perhaps some way for the application writer to provide hints about where to find the current bean factory though the use of a BeanFactoryLocator or if the application writer figured the bean would only be used in a web context they chould use the WebApplicationContextUtils to obtain the current BeanFactory. Something like that.
I was thinking of modifying creating a new target source similar to AbstractBeanFactoryBasedTargetSource that took a BeanFactoryLocator instead of a BeanFactory and modify the scope utilities to optionally provide a BeanFactoryLocator. Would something like that work? I'm more than happy to create a patch if I thought I was heading down the right direction and that my patch would eventually be accepted.
Mike
Affects: 2.0 M5
Issue Links:
5 votes, 9 watchers
The text was updated successfully, but these errors were encountered: