首页

异常"javax.naming.NameNotFoundException: Name [toa/maDS] is not bound in this Context. Unable to find [toa]."解决方法

标签:exception,java异常,初始化失败,JNDI,Resource,jndi,context.xml,Java命名和目录接口     发布时间:2016-04-28   

一、异常描述

启动Java Web项目无法正常启动,抛出“javax.naming.NameNotFoundException: Name [toa/maDS] is not bound in this Context. Unable to find [toa].”异常,详细日志如下

javax.naming.NameNotFoundException: Name [toa/maDS] is not bound in this Context. Unable to find [toa].@b@    at org.apache.naming.NamingContext.lookup(NamingContext.java:819)@b@    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)@b@    at org.apache.naming.NamingContext.lookup(NamingContext.java:830)@b@    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)@b@    at org.apache.naming.NamingContext.lookup(NamingContext.java:830)@b@    at org.apache.naming.NamingContext.lookup(NamingContext.java:167)@b@    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)@b@    at javax.naming.InitialContext.lookup(InitialContext.java:417)@b@    at com.xwood.system.JndiTemplate$1.doInContext(JndiTemplate.java:96)@b@    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)@b@    at com.xwood.system.JndiTemplate.lookup(JndiTemplate.java:92)@b@    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)@b@    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)@b@    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)@b@    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)@b@    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)@b@    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)@b@    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)@b@    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)@b@    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:378)@b@    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:161)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)@b@    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)@b@    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1079)@b@    at com.xwood.soofa.app.lwc.service.persistence.dao.ibatis.support.SqlMapClientDaoSupport._initDao(SqlMapClientDaoSupport.java:128)@b@    at com.xwood.soofa.app.lwc.service.persistence.dao.ibatis.support.SqlMapClientDaoSupport.afterPropertiesSet(SqlMapClientDaoSupport.java:93)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)@b@    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)@b@    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:437)@b@    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:411)@b@    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:543)@b@    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)@b@    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)@b@    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:298)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)@b@    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)@b@    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)@b@    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)@b@    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)@b@    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)@b@    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)@b@    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)@b@    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)@b@    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)@b@    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)@b@    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)@b@    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)@b@    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)@b@    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)@b@    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)@b@    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)@b@    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)@b@    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)@b@    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)@b@    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)@b@    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)@b@    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)@b@    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)@b@    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)@b@    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)@b@    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)@b@    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:467)@b@    at com.xwood.soofa.web.PispatcherServlet.createWebApplicationContext(PDispatcherServlet.java:25)@b@    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:483)@b@    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:358)@b@    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:325)@b@    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)@b@    at javax.servlet.GenericServlet.init(GenericServlet.java:158)@b@    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)@b@    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)@b@    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)@b@    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210)@b@    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493)@b@    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)@b@    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)@b@    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)@b@    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)@b@    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)@b@    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)@b@    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)@b@    at java.util.concurrent.FutureTask.run(FutureTask.java:266)@b@    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)@b@    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)@b@    at java.lang.Thread.run(Thread.java:745)@b@@b@四月 28, 2016 7:47:41 下午 org.apache.catalina.startup.HostConfig deployDirectory@b@信息: Deployment of web application directory D:z.168.1.8appsapache-tomcat-7.0.54webapps	oa-mgw1.3.0 has finished in 9,855 ms@b@四月 28, 2016 7:47:41 下午 org.apache.coyote.AbstractProtocol start@b@信息: Starting ProtocolHandler ["http-bio-9999"]@b@四月 28, 2016 7:47:41 下午 org.apache.coyote.AbstractProtocol start@b@信息: Starting ProtocolHandler ["ajp-bio-9109"]@b@四月 28, 2016 7:47:41 下午 org.apache.catalina.startup.Catalina start@b@信息: Server startup in 22250 ms

二、解决步骤

1.  点击项目关于tomcat服务Servers配置的项,在Context.xml添加Resource的JNDI的目录资源注入

异常"javax.naming.NameNotFoundException: Name [toa/maDS] is not bound in this Context. Unable to find [toa]."解决方法

2. JNDI的Resource的格式参考模板如下

<Resource driverClassName="oracle.jdbc.driver.OracleDriver" maxActive="4" maxIdle="2"@b@@b@ maxWait="50" name="toa/maDS" password="1234" type="javax.sql.DataSource" url="jdbc:oracle:thin:@172.168.1.8:1526:d0toa" username="toadata"/>

3. 重启服务,问题解决了 

<<热门下载>>