[英]Issue with Browser Connectivity to a WebSphere Application Server 6.1
[英]EJB Lookup Issue with WebSphere Application Server 6.1
首先,我想告訴您這里曾問過類似類型的問題,但仍然找不到我的問題的解決方案。
我有一個EJB 3項目(名稱= HelloWorldEJBProject)。 我在那里創建了一個無狀態的遠程EJB(名稱= HelloWorldEJB)。 我還在那里創建了一個遠程接口(名稱= HelloWorldEJBInterfaceRemote)。 之后,在使用ant編譯所有內容之后,我將創建一個jar和項目的耳朵。 然后,我將EAR部署在WebSphere Application Server 6.1中。
接下來,我還創建了一個獨立的Java項目(名稱= HelloWorldClient),將HelloWorldEJBProject的jar放入此項目的構建路徑。 現在,當我進行查找時,我遇到了錯誤。
HelloWorldEJB.java:
package com.staples.ejb;
import com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote;
import javax.ejb.Stateless;
@Stateless
public class HelloWorldEJB implements HelloWorldEJBInterfaceRemote {
public HelloWorldEJB() {
}
public String helloWorld() {
return "Hello World";
}
}
Client.java(內部HelloWorldClient項目):
package com.staples.client.processor;
import com.staples.client.util.ApplicationUtil;
import com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote;
public class Client {
static private HelloWorldEJBInterfaceRemote helloInterface = ApplicationUtil.getHelloEJBHandle();
public static void main(String[] args) {
System.out.println(helloInterface.helloWorld());
}
}
ApplicationUtil.java(在HelloWorldClient項目內部):
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote;
public class ApplicationUtil {
public static Object getContext(){
Object obj = null;
Context context;
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL,"corbaloc:iiop:localhost:2811");
Context ctx = new InitialContext(env);
obj = ctx.lookup("ejb/HelloEAR/Hello.jar/HelloWorldEJB#" + HelloWorldEJBInterfaceRemote.class.getName());
} catch (NamingException e) {
e.printStackTrace();
}
return obj;
}
public static HelloWorldEJBInterfaceRemote getHelloEJBHandle()
{
Object obj = getContext();
HelloWorldEJBInterfaceRemote helloInterface = (HelloWorldEJBInterfaceRemote) PortableRemoteObject.narrow(obj, HelloWorldEJBInterfaceRemote.class);
//HelloWorldEJBInterfaceRemote helloInterface = (HelloWorldEJBInterfaceRemote) obj;
return helloInterface;
}
錯誤:
Exception in thread "P=141210:O=0:CT" java.lang.ClassCastException: Unable to load class: com.staples.ejb.interfaces._HelloWorldEJBInterfaceRemote_Stub
at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:372)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:156)
at com.staples.client.util.ApplicationUtil.getHelloEJBHandle(ApplicationUtil.java:41)
at com.staples.client.processor.Client.main(Client.java:14)
如果我評論以下內容
HelloWorldEJBInterfaceRemote helloInterface = (HelloWorldEJBInterfaceRemote) PortableRemoteObject.narrow(obj, HelloWorldEJBInterfaceRemote.class);
並取消注釋以下內容:
HelloWorldEJBInterfaceRemote helloInterface = (HelloWorldEJBInterfaceRemote) obj;
然后出現以下錯誤:
Exception in thread "P=346416:O=0:CT" java.lang.ClassCastException: org.omg.stub.java.rmi._Remote_Stub incompatible with com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote
at com.staples.client.util.ApplicationUtil.getHelloEJBHandle(ApplicationUtil.java:42)
at com.staples.client.processor.Client.main(Client.java:14)
我正在使用EJB 3,所以我想我不需要PortableRemoteObject.narrow,但是如果不使用它,則會出現不同的錯誤。 我也不確定寫什么作為context.lookup()的參數。 我是EJB的新手。 有人可以幫我嗎? 提前致謝。 感謝MagicWand和bkail解決我的port&jndi問題。
開始獲取NamingException
,請使用com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote
作為您的JNDI
查找字符串。 您是否也嘗試過使用它?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.