简体   繁体   English

javax.naming.NameNotFoundException:名称[comp / env]未绑定在此Context中

[英]javax.naming.NameNotFoundException: Name [comp/env] is not bound in this Context

I'm developing a spring application which uses tomcat server managed connection pool. 我正在开发一个使用tomcat服务器管理连接池的spring应用程序。

I defined datasource in tag in context.xml of tomcat: (i am using spring 2.0.7) in context.xml: 我在tomcat的context.xml中的tag中定义了数据源:(我使用的是spring 2.0.7)在context.xml中:

<context>
    <Resource name="jdbc/irb_prod"
    auth="Container"
    type="javax.sql.DataSource"
    factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
    username="xxx"
     password="xxx"
     driverClassName="oracle.jdbc.driver.OracleDriver"
     url="jdbc:oracle:thin:@xxx:1521:xxx"
     maxWait="1000"
     removeAbandoned="true"
     maxActive="5"
     maxIdle="5"
     removeAbandonedTimeout="60"
     logAbandoned="true"/>
</context>

And in my ApplicationContext.xml(ie in spring configuration file) , the code is: 在我的ApplicationContext.xml中(即在spring配置文件中) ,代码是:

     <bean id="dataSource" 
     class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
    <value>java:comp/env/jdbc/irb_prod</value>
    </property>
    </bean>


 <!-- Transaction manager for a single JDBC DataSource -->
    <bean id="transactionManager" 
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource"><ref local="dataSource"/></property>
    </bean>

When the application starts, I get the following errors: 应用程序启动时,我收到以下错误:

javax.naming.NameNotFoundException: Name java:/comp/env/mypool is not bound in this              Context
org.apache.naming.NamingContext.lookup(NamingContext.java:803)
org.apache.naming.NamingContext.lookup(NamingContext.java:159)
org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
javax.naming.InitialContext.lookup(Unknown Source)
org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:132)
org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:130)
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:155)
org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:93)
org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java :197)
org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:184)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInit         ialization(AbstractApplicationContext.java:736)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractAppli  cationContext.java:369)
org.springframework.context.support.ClassPathXmlApplicationContext.<init> (ClassPathXmlApplicationContext.java:123)
org.springframework.context.support.ClassPathXmlApplicationContext.<init>  (ClassPathXmlApplicationContext.java:66)
MainServlet.init(MainServlet.java:21)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java :188)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

please help me to solve this problem. 请帮我解决这个问题。

I faced similar problem with tomcat and did the following in eclipse to solve it: 我遇到了与tomcat类似的问题,并在eclipse中做了以下事情来解决它:

  1. In the server's context.xml, included the jdbc connection details. 在服务器的context.xml中,包含了jdbc连接详细信息。
  2. Stop the server 停止服务器
  3. Clean the project( Project --> Clean ) , the tomcat server ( Server--> Right Click --> Clean ) and Tomcat work directory ( Server--> Right Click--> Clean Tomcat Work Directory ). 清理项目( Project --> Clean ),tomcat服务器( Server--> Right Click --> Clean )和Tomcat工作目录( Server--> Right Click--> Clean Tomcat Work Directory )。
  4. Start the server and run. 启动服务器并运行。

Even after maintaining the details in context.xml, sometimes it might not get reflected. 即使在context.xml中维护了细节之后,有时也可能无法反映出来。 In such cases follow step#3 and hope it helps. 在这种情况下,请按照步骤#3进行操作并希望有所帮

Please update your web.xml with the something similar to the following tag 请使用类似于以下标记的内容更新您的web.xml

<resource-env-ref>
  <description>DataSource
  </description>
  <resource-env-ref-name>
    dbc/irb_prod
  </resource-env-ref-name>
  <resource-env-ref-type>
    javax.sql.DataSource
  </resource-env-ref-type>
</resource-env-ref>

You need to refer this link too for more information 您还需要参考此链接以获取更多信息

That will in case of Tomcat happen when you have for some reason dropped arbitrary servletcontainer-specific JARs such as jsp-api.jar, servlet-api.jar, catalina.jar, etc in webapp's /WEB-INF/lib. 在Tomcat发生的情况下,当你出于某种原因在webapp的/ WEB-INF / lib中丢弃任意特定于servlet容器的JAR,如jsp-api.jar,servlet-api.jar,catalina.jar等。 You should remove all servletcontainer-specific JARs from there, they do not belong there. 您应该从那里删除所有特定于servletcontainer的JAR,它们不属于那里。

在我的情况下,我似乎必须首先关闭我的文件浏览器(FreeCommander XE),然后执行eclipse清理(项目和服务器),确保关闭任何其他程序,可能有处理部署的文件,即使文件不是再打开那些节目

In Eclipse : make sure you have the right context.xml file. 在Eclipse中 :确保您拥有正确的context.xml文件。 This especially valid when you have installed multiple servers . 当您安装了多个服务器时,这尤其有效。

In your Servers tab -> Right click on your deployed web module -> Browse Deployment Location -> ../conf/context.xml. 在Servers选项卡中 - >右键单击已部署的Web模块 - > Browse Deployment Location - > ../conf/context.xml。 Make sure this is the file you want to be using. 确保这是您要使用的文件。

I hope this saves you some time, as I wasted some time on it. 我希望这能节省你一些时间,因为我浪费了一些时间。

在此输入图像描述

在此输入图像描述

暂无
暂无

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

相关问题 javax.naming.NameNotFoundException:名称java:comp在此上下文中未绑定 - javax.naming.NameNotFoundException: Name java:comp is not bound in this Context 自定义SessionListener,此上下文中未绑定名称,javax.naming.NameNotFoundException - Custom SessionListener, name is not bound in this context, javax.naming.NameNotFoundException @Named批注无法在Servlet中加载Bean-javax.naming.NameNotFoundException:此上下文中未绑定名称学生 - @Named annotation can't load a bean in a Servlet - javax.naming.NameNotFoundException: Name student is not bound in this Context javax.naming.NameNotFoundException:名称[jdbc / skynetdb]未绑定在此Context中。 找不到[jdbc] - javax.naming.NameNotFoundException: Name [jdbc/skynetdb] is not bound in this Context. Unable to find [jdbc] javax.naming.NameNotFoundException:名称[SessionFactory]未绑定在此Context中。 无法找到[SessionFactory] - javax.naming.NameNotFoundException: Name [SessionFactory] is not bound in this Context. Unable to find [SessionFactory] javax.naming.NameNotFoundException: fsmDS 未绑定 - javax.naming.NameNotFoundException: fsmDS not bound JNDI失败,并出现javax.naming.NameNotFoundException:在部署Spring Boot2 Tomcat 9时,此上下文未绑定名称[jdbc / Database] - JNDI fails with javax.naming.NameNotFoundException:Name [jdbc/Database] is not bound in this Context when deploying Spring Boot2 Tomcat 9 NO EMBEDDED 在Hibernate 4.3.5 Final上JNDI查找失败-javax.naming.NameNotFoundException:名称[xxx]在此上下文中未绑定。 找不到[xxx] - JNDI look up fails on Hibernate 4.3.5 final - javax.naming.NameNotFoundException: Name [xxx] is not bound in this Context. Unable to find [xxx] Spring Boot构建正常,但抛出javax.naming.NameNotFoundException:剩余名称:运行时的env / jmx / runtime - Spring Boot builds fine but throws javax.naming.NameNotFoundException: remaining name: env/jmx/runtime when running javax.naming.NameNotFoundException:CDIExtension - javax.naming.NameNotFoundException: CDIExtension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM