wildfly/infinispan http会话复制在解组cglib会话bean时遇到classnotfoundexception

e5njpo68  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(371)

我正在运行wildfly 20.0.1.final standalone ,两节点群集。我正在尝试实现节点之间的http会话共享。
在我的springweb应用程序中 <distributable/> 在我的 web.xml .
我的会话对象是:

package my.package;

@Component
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.INTERFACES)
public class MySessionBean implements Serializable {
  // omitted for brevity
}

如你所见,我有 ScopedProxyMode.TARGET_CLASS .
但是,当我在wildfly中执行故障转移时,我的http会话无法恢复,因为我遇到以下警告:

2021-02-22 13:24:18,651 WARN  [org.wildfly.clustering.web.infinispan] (default task-1) WFLYCLWEBINF0007: 
Failed to activate attributes of session Pd9oI0OBiZSC9we0uXsZdBwkLnadO1l4TUfvoJZf: 
org.wildfly.clustering.marshalling.spi.InvalidSerializedFormException: 
java.lang.ClassNotFoundException: my.package.MySessionBean$$EnhancerBySpringCGLIB$$9c0fa1df 
from [Module "deployment.myDeployment.war" from Service Module Loader]
...
Caused by: java.lang.ClassNotFoundException: my.package.MySessionBean$$EnhancerBySpringCGLIB$$9c0fa1df from [Module "deployment.myDeployment.war" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:398)
    at org.jboss.marshalling@2.0.9.Final//org.jboss.marshalling.ModularClassResolver.resolveClass(ModularClassResolver.java:133)
    at org.jboss.marshalling.river@2.0.9.Final//org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:1033)
    at org.jboss.marshalling.river@2.0.9.Final//org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1366)
    at org.jboss.marshalling.river@2.0.9.Final//org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:283)
    at org.jboss.marshalling.river@2.0.9.Final//org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:216)
    at org.jboss.marshalling@2.0.9.Final//org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
    at org.wildfly.clustering.marshalling.spi@20.0.1.Final//org.wildfly.clustering.marshalling.spi.util.MapExternalizer.readObject(MapExternalizer.java:65)
...

请注意 ClassNotFoundException 抱怨是因为缺乏 my.package.MySessionBean$$EnhancerBySpringCGLIB$$9c0fa1df ,这是我的Spring增强豆 MySessionBean 豆子。
正在更改为 ScopedProxyMode.INTERFACES 不是一个选择。
你能用这个给我指出正确的方向吗?

ctehm74n

ctehm74n1#

我通过创建一个名为 MySessionDTO ,并在我的会话中使用它。
所以最初我有这样一个问题(在这个问题中抛出了一个例外):

request.getSession().setAttribute("mySession", mySessionBean);

…在我创造了 MySessionDTO (见下文),我将其重构为:

request.getSession().setAttribute("mySession", mySessionBean.getMySessionDTO());
``` `MySessionDTO` 是一个简单的pojo:

package my.package;

import java.io.Serializable;

public class MySessionDTO extends MySessionBean implements Serializable {
public MySessionDTO (MySessionBean mySessionBean) {
this.setAttributeX(mySessionBean.getAttributeX());
this.setAttributeY(mySessionBean.getAttributeY());
}
}

相关问题