【问题标题】:Spring Boot 2.6.6 upgrade JNDI lookup Failure : Name [java:comp/env/jdbc/testdatasource] is not bound in this context. unable to find [java:comp]Spring Boot 2.6.6 升级 JNDI 查找失败:名称 [java:comp/env/jdbc/testdatasource] 未绑定在此上下文中。无法找到 [java:comp]
【发布时间】:2022-06-30 17:56:40
【问题描述】:

我正在尝试从 Spring Boot 2.2.4.Release 升级到 2.6.6。我在旧版本的 Spring boot 2.2.4 中配置了一个嵌入式 tomcat 服务器,它工作得很好。

@override
protected TomcatWebserver getTomcatWebServer (Tomcat tomcat) {
   System.setProperty("catalina.useNaming","true");
   tomcat.enableNaming();
   return super.getTomcatWebServer(tomcat);
}

@Override
protected void postProcessContext(Context context){
  context.getnamingResources().addResource();
}

private ContextResource testDBResource(){
    ContextResource resource = ContextResource();
    resource.setName("jdbc/testDatasource");
    resource.setType(javax.sql.Datasource.class.getName());
    resource.setProperty("factory", 
    com.zaxxer.hikari.HikariJNDIFactory.class.getName());
    resource.setProperty("url",..);
    resource.setProperty("username",..);
    resource.setProperty("password",..);

}

所以我的 TomcatServletWebserverFactory 配置如上。我留下了几个 为简洁起见配置。在我切换到 2.6.6 版本之前,这绝对可以正常工作。

我确实会查找。

InitialContext jndiContext = new InitialContext();
dataSource = (DataSource)jndiContext.lookup("java:comp/env/jdbc/testDatasource");

然后我在 2.6.6 中得到 NamingException。

在 2.2.4.Release 中,我打印数据源时曾经获取 HikariDataSource (testDataSource)。

请让我知道我必须为 2.6.6 版本进行更多配置。

【问题讨论】:

  • JNDI 在更高版本的 Spring Boot 中被禁用。为什么首先在嵌入式 tomcat 中使用 JNDI?与仅定义数据源并使用它相比,这似乎过于复杂。
  • 感谢@M.Deinum 的回复。您能否让我知道如何再次启用 JNDI。我们通过将 weblogic 上运行的旧项目转换为 Spring Boot/Rest 服务将其迁移到 Spring Boot。 DAO 层可以通过 JNDI 访问 Datasource,我们重用了相同的代码。在我尝试升级到 2.6.6 之前一切正常,甚至 2.5.12 也有同样的问题。

标签: java spring-boot tomcat embedded-tomcat


【解决方案1】:

此问题的任何解决方案? 在将 SpringBoot 版本从 2.1.6 升级到 2.6.6 时,我们也面临同样的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 2015-05-31
    • 1970-01-01
    相关资源
    最近更新 更多