PDA

View Full Version : Using non-serializable reference to service in session scoped bean


koert
Dec 11th, 2006, 07:24 AM
In the JSF/facelets application I am developing, I use several session scoped beans in which I want to use a reference to a (non-serializable) service that is injected with the JSF-Spring variable resolver. Officially, your session scoped bean should be serializable so that the web container can serialize/deserialize this bean without any problems. Because the injected service is not serializable, this will not work. You may get away with ignoring the serializable requirements, but that may cause enormous problems when the application gets a lot of traffic.

I thought about creating a solution with a proxy that holds a transient reference to the service and restores the reference by looking it up in the application context.
Here is the gist of my solution. (http://w.kazed.net:8080/nowhere/space/spring/SerializableReference)

While doing this, I wondered if a similar solution already exists or how other people get around this problem.

Marten Deinum
Dec 11th, 2006, 07:28 AM
I know Wicket (http://www.wicketframework.org) uses a similar approach with proxies for integration with Spring. Maybe it is useable in a certain way.

koert
Dec 12th, 2006, 10:26 AM
I discovered the ScopedProxyFactoryBean (http://www.springframework.org/docs/api/org/springframework/aop/scope/ScopedProxyFactoryBean.html) in Spring; this may be a good solution, although it keeps a valid reference only for the duration of the thread.

Does anyone have experience using this?

Koert