【发布时间】:2019-11-20 12:26:34
【问题描述】:
当我尝试使用 JNDI 将 Spring Boot 应用程序从 STS (eclipse) 部署到 tomcat 9 容器(嵌入式服务器已关闭从 pom 中排除)时,它失败并显示以下消息:
“javax.naming.NameNotFoundException:名称 [jdbc/Database] 未绑定在此上下文中。无法找到 [jdbc]。”
我已经做了一些尝试来解决它,但问题仍然存在:
- 在 eclipse 工作区中的 tomcat/config dir 和 Server/Tomcat-... 中配置 server.xml 和 context.xml,如下所示: Configuration Tomcat (Eclipse and Server configs Image)
我的应用程序 spring 配置是:
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
application.profiles("production");
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class);
builder.headless(false);
builder.profiles("production");
builder.web(WebApplicationType.NONE);
builder.run(args); }
数据源配置为: JNDI Datasource creation source code Image
我尝试了其他可能的解决方案(例如在应用程序的 META-INF 目录中创建 context.xml),但直到现在都没有任何效果,引发了同样的错误: Error Image
【问题讨论】:
标签: java spring spring-boot tomcat tomcat9