Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to deserialize Spring Session Scoped bean

I have the following session scoped bean:

@ManagedBean
@Component
@Scope(proxyMode= ScopedProxyMode.TARGET_CLASS, value="session")
public class SessionData implements Serializable {}

and I store tomcat sessions in a database. The problem is that, when the application tries to deserialize a stored session, I receive the following error:

 org.apache.catalina.session.PersistentManagerBase.swapIn Error deserializing Session EE913D2ACAD49EB55EDA657A54DFA2CB: {1}
 java.lang.ClassNotFoundException: de.myproject.SessionData$$EnhancerBySpringCGLIB$$768b59b9

It seems that it serialized actually the whole Spring context, and obviously there is no such class de.myproject.SessionData$$EnhancerBySpringCGLIB$$768b59b9 after server restarts, so I receive the aforementioned exception.

Is there a way to avoid this, so that the session-scoped bean is serialized properly?

UPDATE: There is an issue regards this which marked as resolved without comments, however I still face it.

like image 866
vtor Avatar asked May 13 '16 14:05

vtor


1 Answers

Please have a try:

using: import org.springframework.test.util.AopTestUtils;

 Serializable readyToSerialize = AopTestUtils.getUltimateTargetObject(yourInstance);

before serialize it.

Note: this code is usefull to understund the problem, if this work, you have to analyze the project architecture and dependecies, to better accomplish for production code. First of all, why you need to serialize a ScopedProxyMode.TARGET_CLASS

like image 100
Guaido79 Avatar answered Oct 22 '22 10:10

Guaido79