【问题标题】:JNDI fails with javax.naming.NameNotFoundException:Name [jdbc/Database] is not bound in this Context when deploying Spring Boot2 Tomcat 9 NO EMBEDDEDJNDI 因 javax.naming.NameNotFoundException 失败:部署 Spring Boot2 Tomcat 9 时未在此上下文中绑定名称 [jdbc/Database] 未嵌入
【发布时间】:2019-11-20 12:26:34
【问题描述】:

当我尝试使用 JNDI 将 Spring Boot 应用程序从 STS (eclipse) 部署到 tomcat 9 容器(嵌入式服务器已关闭从 pom 中排除)时,它失败并显示以下消息:

“javax.naming.NameNotFoundException:名称 [jdbc/Database] 未绑定在此上下文中。无法找到 [jdbc]。”

我已经做了一些尝试来解决它,但问题仍然存在:

我的应用程序 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


    【解决方案1】:

    问题是 Eclipse STS 中存在配置文件的第三个地方,它位于我的环境中: .metadata.plugins\org.eclipse.wst.server.core\tmp0\conf ,我复制了 context.xml 和服务器。 xml 配置,如图像和问题已解决。

    【讨论】:

    • 解决了这个问题后发现了一个新的:“javax.management.InstanceAlreadyExistsException: Catalina:type=DataSource,class=javax.sql.DataSource” 然后我添加了“factory =”org.apache .tomcat.jdbc.pool.DataSourceFactory””到 server.xml 文件中全局 中的 ,它的工作方式类似于此处的回答:link
    猜你喜欢
    • 2011-09-22
    • 2016-12-08
    • 2018-09-12
    • 2012-09-11
    • 2018-11-02
    • 2017-07-17
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多