我正在使用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>
我不知道,如果我設置任何配置相關的屬性。任何幫助,將不勝感激。
您可以發佈您的服務器的XML呢?謝謝 –
@AbelardChow感謝您編輯的快速評論!幷包括在內。 –
您能否包含一些關於「FlightService」的詳細信息(EJB,JAX-WS服務,數據源等)?根據您正在使用的JNDI查找語法,它看起來像您正在嘗試查找EJB,在這種情況下,獲取EJB引用(如注入)有更簡單的方法。 –