0

I have configured JNDI in server.xml and also in context.xml correctly but I am still facing issue .

I am using Spring 3.2.9, JSF 1.1, JDK 8 and Web deployment module 2.4.

Here is the error I am getting while deploying on Tomcat 8:

INFO: No Spring WebApplicationInitializer types detected on classpath
Jun 01, 2016 1:58:55 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Jun 01, 2016 1:58:56 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myService' defined in class path resource [applicationContext-Business.xml]: Cannot resolve reference to bean 'myDao' while setting bean property 'myDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDao' defined in class path resource [applicationContext-Business.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-Business.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [com.my.datasource.YARD_PRD] is not bound in this Context. Unable to find [com.my.datasource.YARD_PRD].
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDao' defined in class path resource [applicationContext-Business.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-Business.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [com.my.datasource.YARD_PRD] is not bound in this Context. Unable to find [com.my.datasource.YARD_PRD].
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext-Business.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [com.my.datasource.YARD_PRD] is not bound in this Context. Unable to find [com.my.datasource.YARD_PRD].
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 34 more
Caused by: javax.naming.NameNotFoundException: Name [com.my.datasource.YARD_PRD] is not bound in this Context. Unable to find [com.my.datasource.YARD_PRD].
at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:157)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
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:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
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:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 41 more
  1. My Server.xml configuration is:

       <Resource auth="Container"
             driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
             maxActive="20"
             name="com.my.datasource.YARD_PRD"
             password="password"
             testOnBorrow="false"
             testWhileIdle="true"
             timeBetweenEvictionRunsMillis="60000"
             type="javax.sql.DataSource"
             url="jdbc:sqlserver://YARD_DEV.my.com:1433;databaseName=YARD_DEV"
             username="username" 
             validationQuery="SELECT 1"/> 
    
  2. My Context.xml configuration is:

      <ResourceLink global="com.my.datasource.YARD_PRD" name="com.my.datasource.YARD_PRD" type="javax.sql.DataSource"/>
    
vvvvv
  • 25,404
  • 19
  • 49
  • 81
  • Add your config's to the question... – KlajdPaja Jun 01 '16 at 09:55
  • server.xml is – Shital Bisen Jun 01 '16 at 10:12
  • From this: [Name jdbc/mydb is not bound in this Context](http://stackoverflow.com/questions/22545169/name-jdbc-mydb-is-not-bound-in-this-context) and this [javax.naming.NameNotFoundException](http://stackoverflow.com/questions/16737754/javax-naming-namenotfoundexception-name-is-not-bound-in-this-context-unable-to)... The only thing you might be misssing is the web.xml config, hope these heps. – KlajdPaja Jun 01 '16 at 10:26
  • I've also configured in WEB-INF/web.xml like : DB Connection com.jbhunt.datasource.YARD_DEV javax.sql.DataSource Container – Shital Bisen Jun 01 '16 at 10:45
  • You have a mismatche than com.jbhunt.datasource.YARD_DEV vs com.my.datasource.YARD_PRD – KlajdPaja Jun 01 '16 at 10:46
  • sorry It's actullay YARD_PRD only by mistake I put here YARD_DEV . – Shital Bisen Jun 01 '16 at 10:57
  • and the part jbhunt vs my ?!!! – KlajdPaja Jun 01 '16 at 10:59
  • it's com.my.datasource.YARD_PRD only , here put the other one . ! Sorry .! – Shital Bisen Jun 01 '16 at 11:01
  • accept the edit's on your post... other people need to see those config too if you want help – KlajdPaja Jun 01 '16 at 12:56
  • 1
    I Solved the issue . actually spring with tomcat take JNDI like "com/env/jdbc/YARD_PRD" not com.my.datasource.YARD_PRD. after changing name like com/env/jdbc/YARD_PRD problem solved . anyway thanks for replying @KLajdPaja .. :) – Shital Bisen Jun 01 '16 at 13:39

0 Answers0