【问题标题】:Jetty JNDI with Oracle error: IllegalStateException: Nothing to bind for name jdbc/replaydev带有 Oracle 错误的 Jetty JNDI:IllegalStateException:Nothing to bind for name jdbc/replaydev
【发布时间】:2018-03-21 08:31:56
【问题描述】:

我编写了一个 JAX-RS REST-API,它从 Oracle 获取行。
为此,我使用了JNDI,因为我使用的是Jetty。但是在部署 WAR 文件时出现以下错误:

Caused by:
java.lang.IllegalStateException: Nothing to bind for name jdbc/replaydev
        at org.eclipse.jetty.plus.webapp.PlusDescriptorProcessor.bindEntry(PlusDescriptorProcessor.java:914)

我的 web.xml 有以下条目:

<resource-ref>
 <res-ref-name>jdbc/replaydev</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
</resource-ref>

WEB-INF/jetty-env.xml 有以下条目:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"    "http://www.eclipse.org/jetty/configure_9_0.dtd">

<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
  <New id="replaydev" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg><Ref refid='wac'/></Arg>
    <Arg>jdbc/replaydev</Arg>
    <Arg>
      <New class="oracle.jdbc.pool.OracleDataSource">
        <Set name="URL">jdbc:oracle:thin://@MY.ORACLE.SERVER:1555/JOBCTL</Set>
        <Set name="User">XYZ</Set>
        <Set name="Password">rockOn</Set>
        <Set name="connectionCachingEnabled">true</Set>
      </New>
    </Arg>
  </New> 
</Configure>

我的 Java 代码如下:

Context initContext = new InitialContext();
ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/replaydev");

con = ds.getConnection();
Class.forName("oracle.jdbc.OracleDriver");

POM.xml 添加了以下依赖项:

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-server</artifactId>
    <version>9.2.11.v20150529</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-webapp</artifactId>
    <version>9.2.11.v20150529</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-plus</artifactId>
    <version>9.2.11.v20150529</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-jndi</artifactId>
    <version>9.2.11.v20150529</version>
</dependency>

我什至尝试在 web.xml 条目中添加 id 标签,例如:&lt;resource-ref id="replaydev"&gt;....&lt;/resource-ref&gt; for jetty-env.xml &lt;New id="replaydev" class="org.eclipse.jetty.plus.jndi.Resource"&gt;。它也不起作用。

我错过了什么吗??

【问题讨论】:

  • Jetty 9.2 is EOL (End of Life),考虑升级。
  • 你能试试没有额外的/(在java:部分之后) - 又名:ds = (DataSource)initContext.lookup("java:comp/env/jdbc/replaydev");

标签: java rest jetty jax-rs jndi


【解决方案1】:

配置看起来不错。我猜你正在使用maven。确保您正在部署带有这些修改的 jetty.xml 版本。例如:mvn clean install

【讨论】:

    【解决方案2】:

    感谢@voodoo14 和@joakim。
    我找到了灵魂。我实际上在 POM.xml
    中删除了上面显示的依赖项 这是因为我已经运行了一个独立的 jetty v9。而且我相信上面提到的依赖关系正在创造一个更多的码头。
    所以我删除了依赖项并且一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-31
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 2018-02-26
      • 2023-03-09
      • 1970-01-01
      相关资源
      最近更新 更多