【发布时间】:2017-02-13 21:36:49
【问题描述】:
我正在使用 IBM WebSphere Application Server Liberty 来执行 JNDI 查找。我很确定要正确了解项目中资源的位置。但是,当我运行它时,我得到一个 name not found 错误。
这是执行查找的代码:
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 引用(例如注入)。