0

I get the below error while moving from XML to Java config in spring boot.

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
at org.apache.tomcat.websocket.server.WsServerContainer.<init>(WsServerContainer.java:149) ~[tomcat-embed-websocket-8.0.32.jar:8.0.32]
at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131) ~[tomcat-embed-websocket-8.0.32.jar:8.0.32]
at org.apache.tomcat.websocket.server.WsContextListener.contextInitialized(WsContextListener.java:39) ~[tomcat-embed-websocket-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4812) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) [tomcat-embed-core-8.0.32.jar:8.0.32]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_172]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_172]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_172]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_172]

I get this error when I remove @ImportResource("classpath:applicationContext.xml") from the SpringBootServletInitializer extending class.

I have checked the servlet api version in pom dependency hierarchy and it is set to 3.0.1 and there is only one servlet api dependency and no conflicting lower version.

I'm using spring boot version 1.3.3.RELEASE.

Vijay G
  • 21
  • 6
  • Have you looked at [this question?](https://stackoverflow.com/questions/34950164/getting-nosuchmethoderrorjavax-servlet-servletcontext-getvirtualservername) – Prashant Jul 19 '18 at 07:20
  • You are right @Prashant. [This answer](https://stackoverflow.com/a/47503564/3733369) is very wide and complete – Rcordoval Jul 19 '18 at 07:26
  • Yes, but wondering why its not an issue when I use xml config. Also adding javax.servlet javax.servlet-api 3.1.0 is not helping. – Vijay G Jul 19 '18 at 07:36

1 Answers1

0

getVirtualServerName has been added in ServletContext in Servlet 3.1.

Please, update your servlet-api to the latest version.

Rcordoval
  • 1,932
  • 2
  • 19
  • 25
  • I had 3.0.1 servlet api version in my pom and I mistook it to be 3.1 and expected it to have the getVirtualServerName. I removed the 3.0.1 servlet api dependency and I'm no longer getting this error. – Vijay G Jul 19 '18 at 08:02