相关疑难解决方法(0)

如何使用嵌入式Tomcat将JNDI数据库连接与Spring Boot和Spring Data连接?

当我尝试使用Spring Boot和Spring Data JPA使用嵌入式Tomcat服务器的JNDI数据源时,在使用SpringApplication.run运行应用程序时出现以下错误消息:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Instantiation of bean failed; 
nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilder)] threw exception;
nested exception is org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; 
nested exception is javax.naming.NameNotFoundException: Name [comp/env/jdbc/myDataSource] is not bound in this Context. Unable to find [comp].
Run Code Online (Sandbox Code Playgroud)

我使用如何在Spring Boot with Embedded Tomcat Container中创建JNDI上下文的解决方案中描述的配置

唯一的区别是对org.springframework.boot的额外Maven依赖:spring-boot-starter-data-jpa

这是一个示例项目:https://github.com/derkoe/spring-boot-sample-tomcat-jndi(这是解决方案中示例的修改版本).只需签出,构建并运行SampleTomcatJndiApplication.

看起来用于查找数据库连接的JNDI上下文不是来自webapp的上下文.这似乎是Spring上下文和Tomcat服务器初始化中的排序问题.

任何想法如何解决?

spring-boot embedded-tomcat-8

2
推荐指数
1
解决办法
6836
查看次数

标签 统计

embedded-tomcat-8 ×1

spring-boot ×1