我試圖從Java EE客戶機應用程序訪問EJB3,但一直只能查找失敗。客戶端應用程序在Java EE應用程序客戶端容器中運行。Java EE應用程序客戶機中的EJB3 JNDI查找失敗
我的Java EE應用程序'CoreServer'公開了一些帶有遠程接口的bean。從部署在同一個GlassFish v3.0.1上的Web應用程序訪問它們時,我沒有任何問題。
現在,我試圖從一個客戶端應用程序訪問:
public class Main {
public static void main(String[] args) {
CampaignControllerRemote bean = null;
try {
InitialContext ctx = new InitialContext();
bean = (CampaignControllerRemote) ctx.lookup("java:global/CoreServer/CampaignController");
} catch (Exception e) {
System.out.println(e.getMessage());
}
if (bean != null) {
Campaign campaign = bean.get(361);
if (campaign != null) {
System.out.println("Got "+ campaign);
}
}
}
}
當我運行部署到GlassFish和從appclient運行它,我得到這個錯誤:
Lookup failed for 'java:global/CoreServer/CampaignController' in SerialContext targetHost=localhost,targetPort=3700,orb'sInitialHost=localhost,orb'sInitialPort=3700
但是,當我從WebApplication查找bean(通過SessionContext,而不是InitialContext - 這很重要嗎?)時,我使用的是完全相同的JNDI名稱。另外,當我部署'CoreServer'時,Glassfish報告:
Portable JNDI names for EJB CampaignController : [java:global/CoreServer/CampaignController!mvs.api.CampaignControllerRemote, java:global/CoreServer/CampaignController]
Glassfish-specific (Non-portable) JNDI names for EJB CampaignController : [mvs.api.CampaignControllerRemote, mvs.api.CampaignControllerRemote#mvs.api.CampaignControllerRemote]
我嘗試了所有四個名字,都沒有工作。 appclient是否無法使用(僅)遠程接口訪問bean?
我會建議您切換到使用依賴注入兩個用例...(你的web應用程序和應用程序客戶端)。 – vkraemer 2010-05-12 05:13:38
在應用程序客戶機上依靠注入完成CORBA查找是如何完成的?你可以說得更詳細點嗎? – Thufir 2015-03-11 15:43:10