【问题标题】:Wildfly / Infinispan HTTP session replication hits ClassNotFoundException when unmarshalling CGLIB Session BeanWildfly / Infinispan HTTP 会话复制在解组 CGLIB 会话 Bean 时遇到 ClassNotFoundException
【发布时间】:2023-04-10 01:59:01
【问题描述】:

我在 standalone 中运行 Wildfly 20.0.1.Final,两节点集群。我正在尝试在节点之间实现 HTTP 会话共享。

在我的 Spring Web 应用程序中,我的 <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,这是我的 MySessionBean bean 的 Spring 增强 bean。

不能更改为ScopedProxyMode.INTERFACES

你能指出我正确的方向吗?

【问题讨论】:

  • 获得ClassNotFoundException 的 10 个原因中有 9 个是由于依赖版本不兼容。所以我会从那里开始。

标签: spring spring-security wildfly infinispan


【解决方案1】:

我设法通过创建一个名为 MySessionDTO 的简单 POJO 并在我的会话中使用它来解决此问题。

所以最初我有这个(这引发了问题中的异常):

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());
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-10
    • 2020-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    • 2015-05-26
    相关资源
    最近更新 更多