2017-02-13 161 views
0

我正在使用IBM WebSphere Application Server Liberty來執行JNDI查找。我很確定正確地說明項目中資源的位置。但是,當我運行這個我得到一個名稱未找到錯誤。無法使用IBM WebSphere Application Server執行JNDI查找Liberty

這裏是執行查找代碼:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{ 
    PrintWriter out = response.getWriter(); 
    response.setContentType("text/html"); 
    try { 
     FlightService flightService = (FlightService)new InitialContext().lookup("java:comp/Web1/FlightService!com.airline.FlightService"); 
    } 
    catch(Exception ex){ 
     ex.printStackTrace(); 
    } 
    if(flightService !=null){ 
     out.println(flightService.getAirplaneModel()); 
     out.println(flightService.getFrom()); 
     out.println(flightService.getTo()); 

    } 
} 

這裏是在server.xml:

<server description="new server"> 

    <!-- Enable features --> 
    <featureManager> 
     <feature>webProfile-7.0</feature> 
     <feature>localConnector-1.0</feature> 
    </featureManager> 

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" --> 
    <httpEndpoint httpPort="9090" httpsPort="9443" id="defaultHttpEndpoint"/> 

    <!-- Automatically expand WAR files and EAR files --> 
    <applicationManager autoExpand="true"/> 


    <applicationMonitor updateTrigger="mbean"/> 

    <webApplication id="Web1" location="Web1-0.0.1-SNAPSHOT.war" name="Web1"/> 
</server> 

我不知道,如果我設置任何配置相關的屬性。任何幫助,將不勝感激。

+0

您可以發佈您的服務器的XML呢?謝謝 –

+0

@AbelardChow感謝您編輯的快速評論!幷包括在內。 –

+0

您能否包含一些關於「FlightService」的詳細信息(EJB,JAX-WS服務,數據源等)?根據您正在使用的JNDI查找語法,它看起來像您正在嘗試查找EJB,在這種情況下,獲取EJB引用(如注入)有更簡單的方法。 –

回答

0

看着服務器xml。我沒有看到JNDI條目被定義。 根據代碼,它應該嘗試從servlet訪問JNDI條目。在這種情況下,你首先在哪裏定義你的JNDI條目?

我認爲你需要以下定義在服務器XML的JNDI項

https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_dep_jndi_refentry.html

請試試看

+0

並非所有的JNDI資源都需要在server.xml中註冊爲「」元素。可以在JNDI中註冊EJB,JDBC數據源和許多其他資源,而server.xml中不存在任何配置。 –

+0

@AndyGuibert我還沒有得到你的觀點。我讀了那裏寫了什麼,但我無法得到我正在尋找的細節 –

+0

我在問什麼類型的對象的FlightService類。它是ejb嗎?它是一個Web服務嗎? –

相關問題