我正在使用WebSphere Application Server 8.0.0.1。 我有两个企业应用程序在同一个jvm中运行(目前)。
我需要远程调用EJB方法
申请("服务") 接口:
package myfirstpackage.ejb3;
@Remote
public interface TriggerManually {
public boolean runTask(String taskName);
public boolean resetTasks();
}
实现:
package anotherpackage.ejb.remoteclient;
@Stateless
public class TriggerManuallyBean implements TriggerManually {
@Override
public boolean runTask(String taskName) {
//Syso...
return false;
}
@Override
public boolean resetTasks() {
//Syso...
return false;
}
}
应用程序("客户端")使用该服务(接口是共享的)
public class TriggerManuallyClient {
public void test() {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
props.put(javax.naming.Context.PROVIDER_URL, "iiop://localhost:2811");
TriggerManually triggerManually;
try {
InitialContext ctx = new InitialContext(props);
triggerManually = (TriggerManually) ctx
.lookup("myjdniname");
triggerManually.resetTasks();
} catch (NamingException e) {
e.printStackTrace();
}
}
}
但是我在查找过程中遇到了类强制转换异常:
Exception created : [java.lang.ClassCastException: myfirstpackage.ejb3._TriggerManually_Stub incompatible with anotherpackage.ejb.remoteclient.TriggerManually
at anotherpackage.ejb.remoteclient.TriggerManuallyClient.test(TriggerManuallyClient.java:20)
at com.ibm._jsp._status._jspService(_status.java:112)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1147)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:722)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:449)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:205)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:919)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1016)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:886)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1655)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)
我认为在EJB 3中我不必创建存根。我该如何解决我的问题?
答案 0 :(得分:1)
问题不在于通过查找返回的存根(以及那些仍存在于EJB3中的存根)。
仔细查看ClassCastException
:
myfirstpackage.ejb3._TriggerManually_Stub incompatible with anotherpackage.ejb.remoteclient.TriggerManually
您可能在TriggerManually
包中也有一个anotherpackage.ejb.remoteclient
课程。
这可能会解决它:
myfirstpackage.ejb3.TriggerManually triggerManually;
try {
InitialContext ctx = new InitialContext(props);
triggerManually = (myfirstpackage.ejb3.TriggerManually) ctx.lookup("myjdniname");
triggerManually.resetTasks();
} catch (NamingException e) {
e.printStackTrace();
}