0

I am creating an SpringBoot REST application (using Gradle). It works fine from my Eclipse. When I take the build and run the JAR I'm getting the following error:

java.lang.NoSuchMethodError:
javax.servlet.ServletContext.getContextPath()Ljava/lang/String;
        at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:626)
~[spring-webmvc-3.2.0.RELEASE.jar!/:3.2.0.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598)
~[spring-webmvc-3.2.0.RELEASE.jar!/:3.2.0.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661)
~[spring-webmvc-3.2.0.RELEASE.jar!/:3.2.0.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517)
~[spring-webmvc-3.2.0.RELEASE.jar!/:3.2.0.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
~[spring-webmvc-3.2.0.RELEASE.jar!/:3.2.0.RELEASE]
        at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
~[spring-webmvc-3.2.0.RELEASE.jar!/:3.2.0.RELEASE]

Using jetty server, servlet-api2.5 and jdk1.7

Can anyone please help me resolve this?

Ravindra babu
  • 37,698
  • 11
  • 250
  • 211
janasoft
  • 163
  • 2
  • 3
  • 12
  • Do you have any other (older) versions of servlet.jar included somehow? – Thilo Oct 07 '15 at 10:39
  • Review all your classpath in your eclipse project. Also use eclipse tools to search if there is more than one "ServletContext" class – Dubas Oct 07 '15 at 10:49
  • @Thilo - Nope. I cheked that one. – janasoft Oct 07 '15 at 11:04
  • I ran into the same error the last days, it turned out that I had the wrong (or an older version of a) jar in the lib folder of my application server then I had in the build path of my project. It was not a Spring project but maybe that helps you. – jcomouth Oct 07 '15 at 11:40
  • I found that, a third party JAR causing this problem. If I remove that JAR, its running properly. But I need that JAR too. How to get rid of this? – janasoft Oct 07 '15 at 12:15
  • @janasoft What's the third-party jar? I assume it has the Servlet API embedded in it? If you really need precisely that jar, then you're into the brittle world of ordering your classpath so that the jar containing the version of `ServletContext` that you want to use appears first. – Andy Wilkinson Oct 07 '15 at 12:43
  • @Andy-wilkinson - its a WSDL client jar – janasoft Oct 09 '15 at 07:21
  • Are you sure you've bundled your dependencies in with your JAR? If you want it to run as a standalone executable you'll need to make an uber JAR. – christopher Oct 09 '15 at 11:29

0 Answers0