2017-03-07 177 views
0

我正在Eclipse JavaEE中開發servlet Web應用程序。 應用程序在本地Tomcat服務器上成功部署和啓動。在Eclipse中調試時發生javax.naming.NameNotFoundException

當我在Eclipse啓動的應用程序在調試模式下,我得到了異常的同一臺服務器上:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MedexamDC': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/MedexamDC] is not bound in this Context. Unable to find [jdbc]. 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:736) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677) 
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548) 
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489) 
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 
at javax.servlet.GenericServlet.init(GenericServlet.java:158) 
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183) 
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099) 
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:779) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) 
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495) 
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347) 
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
at java.lang.Thread.run(Unknown Source) 
Caused by: javax.naming.NameNotFoundException: Name [jdbc/MedexamDC] is not bound in this Context. Unable to find [jdbc]. 
at org.apache.naming.NamingContext.lookup(NamingContext.java:817) 
at org.apache.naming.NamingContext.lookup(NamingContext.java:173) 
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163) 
at javax.naming.InitialContext.lookup(Unknown Source) 
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) 
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) 
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) 
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179) 
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) 
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106) 
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231) 
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) 
... 36 more 

мар 07, 2017 4:32:47 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Allocate exception for servlet mvc-dispatcher 
javax.naming.NameNotFoundException: Name [jdbc/MedexamDC] is not bound in this Context. Unable to find [jdbc]. 
at org.apache.naming.NamingContext.lookup(NamingContext.java:817) 
at org.apache.naming.NamingContext.lookup(NamingContext.java:173) 
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163) 
at javax.naming.InitialContext.lookup(Unknown Source) 
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) 
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) 
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) 
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179) 
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) 
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106) 
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231) 
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:736) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677) 
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548) 
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489) 
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 
at javax.servlet.GenericServlet.init(GenericServlet.java:158) 
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183) 
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099) 
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:779) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) 
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495) 
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347) 
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
at java.lang.Thread.run(Unknown Source) 

文件conf/context.xml文件

<Context reloadable="true"> 
<WatchedResource>WEB-INF/web.xml</WatchedResource> 
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> 

<Resource auth="Container" driverClassName="org.postgresql.Driver" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/MedexamDC" password="123" type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5432/medexam" username="postgres"/> 
</Context> 

的webapp \ META_INF \上下文.xml

<Context> 
    <Context path=""/> 
    <ResourceLink type="javax.sql.DataSource" name="jdbc/MedexamDC" global="jdbc/MedexamDC" />  
</Context> 

我出於可能的原因。任何人有任何建議?謝謝。

回答

0

這可能是因爲您沒有使用Tomcat的物理安裝,而是其「複製」,這是Eclipse的默認選項。

如果你看看你的Project Explorer視圖,你會看到有一個Servers項目。看看它,找到你正在使用的Tomcat。

在該Tomcat文件夾中,您將看到一組配置文件。這些是Eclipse用來啓動Tomcat的文件,因此您可以在不損壞物理安裝的情況下使用這些文件。

所有你需要做的就是打開context.xml文件Tomcat的文件夾,這是Servers內內,並粘貼Resource您已經有conf/context.xml

重新啓動你的Tomcat後,它應該工作的罰款。

另一種選擇是告訴Eclipse使用物理安裝。你可以在Servers視圖上做到這一點。雙擊你的Tomcat打開它的配置,在左下角你會看到3個選項。選擇「使用Tomcat安裝」接管已配置的物理安裝。

+0

第一個選項對我不起作用。其次是好的。謝謝! –