java - 发生异常“java.lang.ClassCastException:org.wildfly.naming.client.store.RelativeContext 无法转换为 com..dispatchLogs.IDispatchLogs”
问题描述
我有一个 EJB:
@Stateless
@EJB(name = "LogsTransferService/LoggedDataBean/remote", mappedName = "LogsTransferService/LoggedDataBean/remote", beanInterface = ILoggedData.class)
public class DispatchLogsBean implements IDispatchLogs {
并且接口有@Remote注解:
@Remote
public interface IDispatchLogs {
我正在尝试将其查找为:
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
env.put("jboss.naming.client.ejb.context", true);
InitialContext remoteContext = new InitialContext(env);
Object ejb = remoteContext
.lookup("ejb:DispatchService/DispatchLogsBean!com.nextcontrols.dispatchLogs.IDispatchLogs" + IDispatchLogs.class.getName());
System.out.println(ejb);
IDispatchLogs dEJB=(IDispatchLogs) ejb;
首先,使用我在 EJB 标头中指定的“LogsTransferService/LoggedDataBean/remote”无法访问它。它给出了 Name not found 异常。其次,如果我按照代码所示访问它。name not found 异常消失了,但是发生了 Class cast 异常:
java.lang.ClassCastException: org.wildfly.naming.client.store.RelativeContext cannot be cast to com.dispatchLogs.IDispatchLogs
我在我的 POM 中有这种依赖关系:
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>23.0.2.Final</version>
<type>pom</type>
</dependency>
我正在使用 JDK 8 和 Wildfly 16。
解决方案
推荐阅读
- python - 我需要帮助在 Pandas 中创建一个聚合在一列上的 groupby
- c# - C# Windows 窗体贷款计算器
- javascript - 如何将在所有和最喜欢的报告之间切换的下拉列表转换为反应 js 中的单个按钮?
- node.js - 聚合来自不同集合的数据
- typescript - 如何在方法中执行协变泛型返回类型?
- java - 如果我想从另一个片段中添加书签,为什么我的书签单词没有保存到 sqlite 数据库?
- html - Bootstrap 模板设计和导航栏问题
- laravel - Vue共享组件未显示
- java - Youtube 和其他应用程序未在 Android 11 模拟器上显示
- rust - `HashMap::get_mut` 导致“返回对本地值的引用”,任何有效的解决方法?