3

I am trying to upgrade from Spring Boot 2.2.4.Release to 2.6.6. I have a embedded tomcat server configured in older version of the Spring boot 2.2.4 which works perfectly fine.

@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",..);

}

So my TomcatServletWebserverFactory is configured is like above. I have left few configurations for brevity. This was absolutely working fine until I shifted to 2.6.6 version.

I do lookup like.

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

Then I get the NamingException in 2.6.6.

In 2.2.4.Release I used to get HikariDataSource (testDataSource) when I print the datasource.

Please let me know I have to do any more configurations for 2.6.6 version.

Clifford
  • 88,407
  • 13
  • 85
  • 165
krajesh10
  • 31
  • 1
  • JNDI is disabled in later versions of Spring Boot. Why the JNDI use in an embedded tomcat in the first place? Seems overly complex for this, compared to just define a datasource and use it. – M. Deinum Apr 21 '22 at 05:57
  • Thanks for the reply @M.Deinum. Could you please let me know how to enable JNDI again. we migrated an old project running on weblogic to Spring boot by converting it to Spring Boot/Rest Services. DAO layer has access to Datasource through JNDI we reused the same code. It worked all fine until I tried upgrading to 2.6.6 even 2.5.12 also had the same problem. – krajesh10 Apr 21 '22 at 12:46

0 Answers0