A NoSuchMethodError can be hard to diagnose. They often occur when two different versions of the same class are on the classpath and the wrong one is being used. We can help users by analysing the error and telling them where the class with the missing method was loaded from and all the locations on the classpath where it could be found.
Before:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::
2018-08-10 12:06:36.843 INFO 26153 --- [ main] s.undertow.SampleUndertowApplication : Starting SampleUndertowApplication on aw-rmbp.local with PID 26153 (/Users/awilkinson/dev/spring/spring-boot/1.5.x/spring-boot-samples/spring-boot-sample-undertow/target/classes started by awilkinson in /Users/awilkinson/dev/spring/spring-boot/1.5.x/spring-boot-samples/spring-boot-sample-undertow)
2018-08-10 12:06:36.847 INFO 26153 --- [ main] s.undertow.SampleUndertowApplication : No active profile set, falling back to default profiles: default
2018-08-10 12:06:36.899 INFO 26153 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@59e5ddf: startup date [Fri Aug 10 12:06:36 BST 2018]; root of context hierarchy
2018-08-10 12:06:37.521 INFO 26153 --- [ main] org.xnio : XNIO version 3.3.8.Final
2018-08-10 12:06:37.532 INFO 26153 --- [ main] org.xnio.nio : XNIO NIO Implementation Version 3.3.8.Final
2018-08-10 12:06:37.630 WARN 26153 --- [ main] io.undertow.websockets.jsr : UT026009: XNIO worker was not set on WebSocketDeploymentInfo, the default worker will be used
2018-08-10 12:06:37.630 WARN 26153 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2018-08-10 12:06:37.631 WARN 26153 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;
2018-08-10 12:06:37.638 INFO 26153 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-08-10 12:06:37.644 ERROR 26153 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[classes/:na]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.3.18.RELEASE.jar:4.3.18.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[classes/:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [classes/:na]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [classes/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [classes/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [classes/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [classes/:na]
at sample.undertow.SampleUndertowApplication.main(SampleUndertowApplication.java:26) [classes/:na]
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;
at io.undertow.websockets.jsr.Bootstrap.handleDeployment(Bootstrap.java:92) ~[undertow-websockets-jsr-1.4.25.Final.jar:1.4.25.Final]
at io.undertow.servlet.core.DeploymentManagerImpl.handleExtensions(DeploymentManagerImpl.java:263) ~[undertow-servlet-1.4.25.Final.jar:1.4.25.Final]
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:153) ~[undertow-servlet-1.4.25.Final.jar:1.4.25.Final]
at org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory.createDeploymentManager(UndertowEmbeddedServletContainerFactory.java:416) ~[classes/:na]
at org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory.getEmbeddedServletContainer(UndertowEmbeddedServletContainerFactory.java:238) ~[classes/:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[classes/:na]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[classes/:na]
... 8 common frames omitted
After:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::
2018-08-10 12:08:39.835 INFO 26156 --- [ main] s.undertow.SampleUndertowApplication : Starting SampleUndertowApplication on aw-rmbp.local with PID 26156 (/Users/awilkinson/dev/spring/spring-boot/1.5.x/spring-boot-samples/spring-boot-sample-undertow/target/classes started by awilkinson in /Users/awilkinson/dev/spring/spring-boot/1.5.x/spring-boot-samples/spring-boot-sample-undertow)
2018-08-10 12:08:39.838 INFO 26156 --- [ main] s.undertow.SampleUndertowApplication : No active profile set, falling back to default profiles: default
2018-08-10 12:08:39.890 INFO 26156 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@59e5ddf: startup date [Fri Aug 10 12:08:39 BST 2018]; root of context hierarchy
2018-08-10 12:08:40.506 INFO 26156 --- [ main] org.xnio : XNIO version 3.3.8.Final
2018-08-10 12:08:40.517 INFO 26156 --- [ main] org.xnio.nio : XNIO NIO Implementation Version 3.3.8.Final
2018-08-10 12:08:40.613 WARN 26156 --- [ main] io.undertow.websockets.jsr : UT026009: XNIO worker was not set on WebSocketDeploymentInfo, the default worker will be used
2018-08-10 12:08:40.613 WARN 26156 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2018-08-10 12:08:40.614 WARN 26156 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;
2018-08-10 12:08:40.619 INFO 26156 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-08-10 12:08:40.622 ERROR 26156 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call the method javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader; but it does not exist. Its class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/Users/awilkinson/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar!/javax/servlet/ServletContext.class
jar:file:/Users/awilkinson/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar!/javax/servlet/ServletContext.class
It was loaded from the following location:
file:/Users/awilkinson/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
Note that the failure analysis won't work with Tomcat until we've upgraded to 8.5.33 which will include this change.
Most helpful comment
Before:
After: