Spring Boot Using Embedded Tomcat with JNDI

╄→尐↘猪︶ㄣ 提交于 2019-11-29 11:42:39
Andy Wilkinson

You need to set lookupOnStartup to false on the JndiObjectFactoryBean.

Alternatively, if you need the lookup to work during startup, then this answer may be of interest.

Edit: you've also set the JNDI name on your JndiObjectFactory bean incorrectly. It needs to be java:comp/env/jdbc/myDataSource not jdbc/dataSource.

You use a different name when you're looking up the resource versus when you registered it as the registration automatically places the resource beneath java:comp/env/.

If you are using spring boot, no need for all of that class. It is already configured in @EnableAutoConfiguration or @SpringBootApplication

Just put the following in your application.xml file or equivalent in application.yml file

spring.datasource.driverClassName=JDBCDriverClassName
spring.datasource.url=databaseUrl
spring.datasource.username=databaseUsername
spring.datasource.password=databasePassword
spring.datasource.jndi-name=java:jdbc/dataSource
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!