1

I am converting an existing web application to Spring boot. I am currently facing issues in loading the Spring JNDI datasource. I have added the recommended entries in the application.properties

spring.datasource.mydb.jndi-name=java:comp/env/jdbc/myDB

tried couple of links posted but no luck Configure Mutiple DataSource in Spring Boot with JNDI

Can you please advise for possible solution?

thanks in advance

Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'myDataSource' threw exception; nested exception is org.springframewor
k.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'jdbc/myDb'; nested exception is javax.naming.N
ameNotFoundException: Name [jdbc/myDb] is not bound in this Context. Unable to find [jdbc].
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFacto
ry.java:1128)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:102
3)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'myDataSource' thre
w exception; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with n
ame 'jdbc/myDb'; nested exception is javax.naming.NameNotFoundException: Name [jdbc/myDb] is not bound in this Context. Unable to find [jdbc].
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 24 more
Caused by: org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'jdbc/myDb'; neste
d exception is javax.naming.NameNotFoundException: Name [jdbc/myDb] is not bound in this Context. Unable to find [jdbc].
Community
  • 1
  • 1
san
  • 61
  • 1
  • 9
  • Why would you need a JNDI datasource when running an embedded tomcat... – M. Deinum Dec 16 '16 at 06:50
  • If we do not, then hibernate will complain will say JNDI not found. – san Dec 16 '16 at 19:24
  • Then fix your configuration, hibernate should be using Spring configured datasource and not do a lookup again. – M. Deinum Dec 17 '16 at 13:54
  • i have a separate jar which has hibernate.xml and looking up for configurations using JNDI lookup. this jar is plugged into the .war file. can you please advise on this – san Dec 19 '16 at 16:36
  • Create your own `hibernate.xml` without the JNDI lookup. Adding it to your own war should make that take precedence over the other one. Or if you don't want that you really need to add JNDI to your embedded tomcat, which is not something you really want iMHO. – M. Deinum Dec 20 '16 at 10:31

0 Answers0