【问题标题】:Unable to perform JNDI lookup using IBM WebSphere Application Server Liberty无法使用 IBM WebSphere Application Server Liberty 执行 JNDI 查找
【发布时间】: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 引用(例如注入)。

标签: jndi websphere-liberty


【解决方案1】:

查看服务器 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

请试一试

【讨论】:

  • 并非所有 JNDI 资源都需要在 server.xml 中注册为 &lt;jndiEntry&gt; 元素。 EJB、JDBC 数据源和许多其他资源可以在 JNDI 中注册,而 server.xml 中不存在任何配置。
  • @AndyGuibert 我还是没明白你的意思。我读了那里写的东西,但是我无法得到我正在寻找的细节
  • 我在问 FlightService 类是什么类型的对象。是ejb吗?它是网络服务吗?
  • @mohanbabu,而不是 java:comp,你可以试试 java:app 吗?
  • @AbelardChow 运气不好!
猜你喜欢
  • 2015-12-19
  • 1970-01-01
  • 2018-07-07
  • 1970-01-01
  • 2017-07-31
  • 2017-01-21
  • 2016-11-16
  • 1970-01-01
  • 2014-12-06
相关资源
最近更新 更多