简体   繁体   English

JNDI查找失败(NameNotFoundException)

[英]JNDI lookup failed (NameNotFoundException)

UPDATE : Well, it seems that this is a problem only when I try to debug locally. 更新 :嗯,似乎只有在我尝试在本地调试时这才是问题。 When published on Jetty (not the same machine) it works great. 当发布在Jetty(不是同一台机器)上时,效果很好。 Is it possible to configure the jetty.xml file used by Run-Jetty-Run when debugging locally? 在本地调试时是否可以配置Run-Jetty-Run使用的jetty.xml文件?

I just wasted an afternoon trying to find the cause of this, but with no success... 我只是浪费了一个下午试图找到原因,但没有成功......

I'm setting up a connection pool with c3p0 for my application. 我正在为我的应用程序设置一个带有c3p0的连接池。 I'm using Jetty 7, by the way. 顺便说一句,我正在使用Jetty 7。 The problem is that when I do a context.lookup get a datasource, I get this exception: 问题是,当我执行context.lookup获取数据源时,我得到以下异常:

javax.naming.NameNotFoundException; remaining name 'env/jdbc/DSTest'
at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:634)
at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:665)
at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:680)
at org.eclipse.jetty.jndi.java.javaRootURLContext.lookup(javaRootURLContext.java:113)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.see.metrics.SqlHelper.Initialize(SqlHelper.java:68)
at com.see.metrics.Metrics.Initialize(Metrics.java:45)
at com.see.game.GameProducer.generateMetadata(GameProducer.java:223)
at org.odata4j.producer.mongodb.MongoProducer.initMongo(MongoProducer.java:98)
at org.odata4j.producer.mongodb.MongoProducerFactory.create(MongoProducerFactory.java:55)
at org.odata4j.producer.resources.ODataProducerProvider.newProducerFromFactory(ODataProducerProvider.java:66)
at org.odata4j.producer.resources.ODataProducerProvider.getInstance(ODataProducerProvider.java:48)
at org.odata4j.producer.resources.ODataProducerProvider.getInstance(ODataProducerProvider.java:1)
at com.sun.jersey.core.impl.provider.xml.LazySingletonContextProvider.get(LazySingletonContextProvider.java:80)
at com.sun.jersey.core.impl.provider.xml.LazySingletonContextProvider.access$000(LazySingletonContextProvider.java:52)
at com.sun.jersey.core.impl.provider.xml.LazySingletonContextProvider$1.getValue(LazySingletonContextProvider.java:69)
at com.sun.jersey.server.impl.inject.AbstractHttpContextInjectable$1.getValue(AbstractHttpContextInjectable.java:100)
at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:43)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:119)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:166)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:259)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:990)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1048)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:601)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
at java.lang.Thread.run(Thread.java:662)

I have a jndi.properties file to configure my InitialContext (located in my resource folder src/main/resources) 我有一个jndi.properties文件来配置我的InitialContext(位于我的资源文件夹src / main / resources中)

java.naming.factory.url.pkgs=org.eclipse.jetty.jndi
java.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory

I also have a jetty-env.xml file in the webapp/WEB-INF folder: 我在webapp / WEB-INF文件夹中也有一个jetty-env.xml文件:

<Configure class="org.mortbay.jetty.webapp.WebAppContext">

<!--<Set name="ConfigurationClasses">
   <Ref id="plusConfig"/>
</Set>  -->

<!-- MySql datasource org.eclipse.jetty.plus.jndi.Resource Factory-->
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
        <Set name="url">jdbc:mysql://host/</Set>
        <Set name="username">username</Set>
        <Set name="password">password</Set>
        <Set name="checkoutTimeout">5000</Set>
        <Set name="initialPoolSize">10</Set>
        <Set name="maxIdleTime">30</Set>
        <Set name="maxPoolSize">160</Set>
        <Set name="minPoolSize">10</Set>
        <Set name="maxStatements">200</Set>
        <Set name="maxConnectionAge">0</Set>
        <Set name="acquireIncrement">15</Set>
    </New>
  </Arg>
 </New>
</Configure>

And I added those lines in my web.xml file: 我在web.xml文件中添加了这些行:

<resource-ref>
  <description>DB Connection</description>
  <res-ref-name>jdbc/DSTest</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

I seem to have followed all the required steps, but I still get a javax.naming.NameNotFoundException when doing the lookup... 我似乎已经遵循了所有必需的步骤,但在执行查找时仍然得到javax.naming.NameNotFoundException ...

Any hints? 任何提示?

Thanks! 谢谢!

EDIT : I forgot to put how I do my lookup. 编辑 :我忘记了如何进行查找。

InitialContext ctx = new InitialContext();
DataSource dataSource = (DataSource)ctx.lookup("java:comp/env/jdbc/DSTest");

Stupid question but this page http://docs.codehaus.org/display/JETTY/JNDI#JNDI-resref states that using JNDI with Jetty is an optional feature that needs to be enabled. 愚蠢的问题但是这个页面http://docs.codehaus.org/display/JETTY/JNDI#JNDI-resref表明使用带Jetty的JNDI是一个需要启用的可选功能。

Specifically it says The class that does this is org.mortbay.jetty.plus.webapp.Configuration, and we specify its name in the list of configurations to be applied to the webapp when we define the org.mortbay.jetty.webapp.WebAppContext for it. 具体来说它表示执行此操作的类是org.mortbay.jetty.plus.webapp.Configuration,并且当我们定义org.mortbay.jetty.webapp.WebAppContext时,我们在要应用于webapp的配置列表中指定其名称。为了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM