【问题标题】:Problem with JNDI look-up in WildFly 17: java.lang.ClassCastException: class is in unnamed module of loaderWildFly 17 中的 JNDI 查找问题:java.lang.ClassCastException: class is in unnamed module of loader
【发布时间】:2020-09-30 18:35:56
【问题描述】:

我使用 Wildfly 17 并且有几个无状态 EJB,其中一个会导致我在 JNDI 查找时有时(但并非总是)出现问题。这是我的 EJB:

@Stateless
public class AVeDBService {
  //other stuff here
}

当我部署我的应用程序时,我看到上述服务的以下日志:

java:global/heimdi/AVeDBService!at.home.digest.services.AVeDBService
java:app/heimdi/AVeDBService!at.home.digest.services.AVeDBService
java:module/AVeDBService!at.home.digest.services.AVeDBService
ejb:/heimdi/AVeDBService!at.home.digest.services.AVeDBService
java:global/heimdi/AVeDBService
java:app/heimdi/AVeDBService
java:module/AVeDBService

我有一个单例 ServiceLocator 类,它使用以下 JNDI 名称查找上述服务的存根:

    public class ServiceLocator {

     private static final String AVE_DB_SERVICE_JNDI_KEY = 
     "java:global/heimdi/AVeDBService!at.home.digest.services.AVeDBService";

     private Map<String, Object> serviceHolder = new HashMap<String, Object>();

     private ServiceLocator() {
        try {
            Context ctx = new InitialContext();
            AVeDBService aveDBService = (AVeDBService) ctx.lookup(AVE_DB_SERVICE_JNDI_KEY);
            serviceHolder.put(AVE_DB_SERVICE, aveDBService);
          }

     }

}

现在,当我使用服务定位器获取服务的存根时,有时会出现以下异常。但只是有时:

Caused by: java.lang.ClassCastException: class at.home.digest.services.AVeDBService$$$view39 cannot be cast to class at.home.digest.services.AVeDBService (at.home.digest.services.AVeDBService$$$view39 is in unnamed module of loader 'deployment.heimdi.war' @658d7dca; at.home.digest.services.AVeDBService is in unnamed module of loader 'deployment.heimdi.war' @15cdf490)

我在同一场战争中使用我的服务。模块,在其中声明它(相同的 Web 应用程序)。但是尽管如此,全局查找应该始终有效,或者?这可能是 WildFly 17.0 中的错误吗?我在类似的相关问题中找不到答案,例如:

Portable JNDI Syntax lookup for EJB on Glassfish

what is the difference between jndi binding of module and app in Java ee 6/7?

Cannot be cast to class because they are in unnamed module of loader 'app'

谢谢!

【问题讨论】:

  • 您找到解决方案了吗?我遇到了完全相同的问题。
  • 其实不是。有人告诉我升级 WildFly 版本,但我从来没有找到时间这样做。所以,我的问题仍然存在。
  • 他们推荐了什么版本?我正在使用 18.01.Final 并且仍然可以看到它。
  • @pbuchheit 在我提出问题时,他们推荐了最新版本,我认为是 19 或 20。您每次都看到该消息吗?因为我只是偶尔看到它;在大多数情况下,一切正常,没有任何问题
  • 我每次都看到它,所以我怀疑我的问题是我的某处配置错误。你有一个链接到你问这个问题的地方吗?我有兴趣查看详细信息。

标签: java jakarta-ee jndi service-locator wildfly-17


【解决方案1】:

Wildfly 24.1 也有同样的问题,问题是 EAR 项目中类的 Classloader,我必须按照提供的方式更改 WAR 的 POM 中 EJB 的依赖关系,所以最终的 EAR 只包含一个副本EJB 类,解决了我的问题

POM Example

【讨论】:

    【解决方案2】:

    我想在 Wildfly 21 上部署耳朵时遇到了同样的问题。 为了解决这个问题,我所要做的就是将我所有 Sessions Bean 上的 @Local 注释更改为 @Remote

    【讨论】:

      猜你喜欢
      • 2022-12-04
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-21
      • 1970-01-01
      • 2022-12-27
      • 2013-04-09
      • 1970-01-01
      相关资源
      最近更新 更多