一個應用程序(例如app.EAR)被部署到我自己機器中的JBoss並且正常工作。當我將它部署到遠程JBoss時,它被部署了,但是當我嘗試訪問需要JNDI查找到遠程EJB的功能時,我得到了NameNotFoundException。所以,它似乎無法找到所需的服務。怎麼來的?如果它在本地工作?NameNotFoundException在生產中對遠程EJB進行JNDI查找JBoss(在本地工作)
與遠程EJB接口的依賴關係位於EAR內的lib文件夾中,當然會使用@Remote進行註釋。 JBoss與生產版完全一樣(我將整個JBoss從生產複製到我的機器以檢查是否缺少任何配置)。
我查找代碼是這樣的:
private Object lookup(String resourceName, String loginData) {
if (isPropagateUserCredentials() && (loginData == null || loginData.trim().equals(""))) {
throw new MyInfraConfigException("somemessage");
}
Properties envProperties = new Properties();
envProperties.putAll(this.jndiProperties);
if (loginData != null && !loginData.equals("")) {
envProperties.put(Context.SECURITY_PRINCIPAL, loginData);
envProperties.remove(Context.SECURITY_CREDENTIALS);
}
Context context = null;
try {
context = new InitialContext(envProperties);
return context.lookup(resourceName);
} catch (NameNotFoundException e){
String message = "Resource "+resourceName+" not found.";
LoggerFactory.getInstance(this.getClass().getName()).error(message, e);
throw new com.mypackage.NameNotFoundException(message, e);
} catch (NamingException e) {
String message = "Failed to find resource with JNDI: "+e.getMessage();
LoggerFactory.getInstance(this.getClass().getName()).error(message, e);
throw new com.mypackage.NamingException(message, e);
} finally{
if(context!=null){
try {
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
}
}
的資源名稱是ExternalResource。
堆棧跟蹤低於:
29/06/2015 10:30:43 oracle.j2ee.clustering.ClusteringMessages warningInOpmnGetServers
AVISO: Error in obtaining server list from OPMN on host XX.XXX.XXX.XXX:XXXX. Please verify that OPMN is running.
javax.naming.NameNotFoundException: ExternalResource not found
at com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:60)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at br.teste.TestaJNDI.main(TestaJNDI.java:33)
任何線索?
UPDATE 爲了嘗試連接到服務器並理解問題的原因,創建了一個外部簡單的java應用程序。實際上,問題是我正在連接超時:
javax.naming.CommunicationException: Connection timed out [Root exception is java.net.ConnectException: Connection timed out]
at com.evermind.server.rmi.RMIClient.lookup(RMIClient.java:311)
at com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:59)
at javax.naming.InitialContext.lookup(Unknown Source)
at br.teste.TestaJNDI.listaUFs(TestaJNDI.java:55)
at br.teste.TestaJNDI.main(TestaJNDI.java:37)
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.evermind.server.rmi.RMIClientConnection.createSocket(RMIClientConnection.java:802)
at oracle.oc4j.rmi.ClientSocketRmiTransport.createNetworkConnection(ClientSocketRmiTransport.java:59)
at oracle.oc4j.rmi.ClientRmiTransport.connectToServer(ClientRmiTransport.java:75)
at oracle.oc4j.rmi.ClientSocketRmiTransport.connectToServer(ClientSocketRmiTransport.java:69)
at com.evermind.server.rmi.RMIClientConnection.connect(RMIClientConnection.java:765)
at com.evermind.server.rmi.RMIClientConnection.sendLookupRequest(RMIClientConnection.java:247)
at com.evermind.server.rmi.RMIClientConnection.lookup(RMIClientConnection.java:231)
at com.evermind.server.rmi.RMIClient.lookup(RMIClient.java:302)
... 4 more
請顯示您從失敗的查找 –
獲得的堆棧跟蹤,請顯示引導日誌+異常以及您正在使用哪個jboss版本? – Paizo
@SteveC堆棧跟蹤是非常簡單的: 29/06/2015 10:30:43 oracle.j2ee.clustering.ClusteringMessages warningInOpmnGetServers AVISO:錯誤從OPMN主機10.0.225.75:6003獲取服務器列表。請確認OPMN正在運行。 javax.naming.NameNotFoundException:XXXService未找到 \t在com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:60) \t在javax.naming.InitialContext.lookup(InitialContext.java:392) \t在br.teste.TestaJNDI.main(TestaJNDI.java:33) – jguilhermemv