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.

2
  • 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. Commented Apr 21, 2022 at 5: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. Commented Apr 21, 2022 at 12:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.