Jetty JNDI with Oracle error: IllegalStateException: Nothing to bind for name jdbc/replaydev

Jetty JNDI with Oracle error: IllegalStateException: Nothing to bind for name jdbc/replaydev

我写了一个 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 标签,例如:<resource-ref id="replaydev">....</resource-ref> for jetty-env.xml <New id="replaydev" class="org.eclipse.jetty.plus.jndi.Resource">。它也不起作用。

我是不是漏掉了什么??

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

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