In my app we are force to use a tomcat 8.5 because we have to support servlet api 3.1 but we upgradred to spring boot 2.2.6. and now the problem is happening while starting using the embedded tomcat. If I comment out the tomcat version in my pom (getting Tomcat 9) the same code works like a charm.
This my EmbededTomcat code:
@Value("${spring.datasource.url}")
private String jdbcUrl;
@Value("${spring.datasource.username}")
private String jdbcUsername;
@Value("${spring.datasource.password}")
private String jdbcPassword;
@Value("${spring.datasource.driver-class-name}")
private String driverClassName;
@Bean
public TomcatServletWebServerFactory tomcatFactory() {
log.info("initializing tomcat factory... ");
return new TomcatServletWebServerFactory() {
@Override
protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
tomcat.enableNaming();
return super.getTomcatWebServer(tomcat);
}
@Override
protected void postProcessContext(Context context) {
log.info("initializing tomcat factory JDNI ... ");
// Adding connection details
ContextResource resource = new ContextResource();
resource.setName("jdbc/DB");
resource.setType(DataSource.class.getName());
resource.setProperty("driverClassName", driverClassName);
resource.setProperty("url", jdbcUrl);
resource.setProperty("username", jdbcUsername);
resource.setProperty("password", jdbcPassword);
context.getNamingResources().addResource(resource);
}
};
}
On my pom.xml the only change I made are:
<servlet-api.version>3.1.0</servlet-api.version>
<!-- Forced for embeded tomcats since tomcat 9 force servlet 4.0 -->
<tomcat.version>8.5.54</tomcat.version>
And this is the full stack error:
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:175)
The following method did not exist:
org.apache.tomcat.util.modeler.Registry.disableRegistry()V
The method's class, org.apache.tomcat.util.modeler.Registry, is available from the following locations:
jar:file:/C:/Users/localAdministrator/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.54/tomcat-embed-core-8.5.54.jar!/org/apache/tomcat/util/modeler/Registry.class
It was loaded from the following location:
file:/C:/Users/localAdministrator/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.54/tomcat-embed-core-8.5.54.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.modeler.Registry
Possible related question:
am trying a Spring boot example but it is showing following error.. what should i do?