Link to home
Start Free TrialLog in
Avatar of gp
gpFlag for United States of America

asked on

Tomcat error with spring boot 3.0.5 JDK 17 micro service application

Hi,


I am using Intellij IDEA community version. I have micro service application running on JDK 17 and Spring Boot 3.0.5.


I am getting below type of errors.







15:06:59.942 [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exception

java.lang.NoSuchMethodError: org/apache/catalina/Context.addServletContainerInitializer(Ljakarta/servlet/ServletContainerInitializer;Ljava/util/Set;)V (loaded from file:/C:/Users/xyz/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.69/tomcat-embed-core-9.0.69.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@c547fc93) called from class org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory (loaded from file:/C:/Users/xyz/.m2/repository/org/springframework/boot/spring-boot/3.0.5/spring-boot-3.0.5.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@c547fc93).

   at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.configureContext(TomcatServletWebServerFactory.java:380)

   at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.prepareContext(TomcatServletWebServerFactory.java:258)

   at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:209)

   at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:183)

   at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161)

   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:578)

   at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)

   at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)

   at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)

   at org.springframework.boot.SpringApplication.run(SpringApplication.java:310)

   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304)

   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293)

   at com.aaa.MessageApplication.main(RmsGioMessageApplication.java:21)

15:06:59.959 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - 


***************************

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.configureContext(TomcatServletWebServerFactory.java:380)


The following method did not exist:


    org/apache/catalina/Context.addServletContainerInitializer(Ljakarta/servlet/ServletContainerInitializer;Ljava/util/Set;)V


The calling method's class, org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory, was loaded from the following location:


    jar:file:/C:/Users/xyz/.m2/repository/org/springframework/boot/spring-boot/3.0.5/spring-boot-3.0.5.jar!/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.class


The called method's class, org.apache.catalina.Context, is available from the following locations:


    jar:file:/C:/Users/xyz/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.69/tomcat-embed-core-9.0.69.jar!/org/apache/catalina/Context.class

    jar:file:/C:/Users/xyz/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/10.1.7/tomcat-embed-core-10.1.7.jar!/org/apache/catalina/Context.class


The called method's class hierarchy was loaded from the following locations:


    org.apache.catalina.Context: file:/C:/Users/xyz/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.69/tomcat-embed-core-9.0.69.jar



Action:


Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory and org.apache.catalina.Context



Process finished with exit code 1




My spring boot main application class code is as below.



@SpringBootApplication

@ComponentScan(basePackages = "com.aaa.bbb.ccc")

public class MessageApplication extends SpringBootServletInitializer implements WebApplicationInitializer {

   @Override

   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {

      return application.sources(MessageApplication.class);

   }

   public static void main(String[] args) {

      SpringApplication.run(MessageApplication.class, args);

   }

}


Does spring boot 3.0.5 application automatically looks for tomcat web server?

Does Intellij IDEA community version supports/integrates with tomcat web server.

Intellij IDEA community version SmartPlugin only supports tomcat 6 ?

 JDK 17 may need higher versions of Tomcat like 10 right?

Please advise.




ASKER CERTIFIED SOLUTION
Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gp

ASKER

I deleted tomcat 9 and tomcat 10 jars from .m2 repository. I do not see these errors now.