wiremock: WireMock Servlet API is not compatible with Spring Boot 2
The Servlet API packaged with WireMock standalone is version 3.x whereas Tomcat container used by Spring Boot requires version 4.x. This causes an unresolvable conflict at runtime. Note that this problem cannot be solved by simply manipulating transitive dependencies because the Servlet API is part of the WireMock jar, not a dependency, and the same applies for Tomcat.
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
I found this thread which discusses the same problem.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 6
- Comments: 19 (7 by maintainers)
Ha, thanks for the quick answer @tomakehurst. I almost said the new
wiremock-jre8
doesn’t work because I was getting the same errors. But I noticed that this time I can see the artifact’s dependencies so I tried to force the Servlet version viacompile 'javax.servlet:javax.servlet-api:4.0.1'
in Gradle. And guess what? It worked 😃 All the tests are green now.Thank you very much, WireMock is an amazing tool!
Any progress here? There seems to be an interaction with the jdk used - with jdk8 we can build/run our tests - with jdk11 its the good old ‘java.lang.NoSuchMethodError’ from above. (Using Spring-cloud-contract-wiremock 2.2.1.
Seems like jetty is not in a hurry of supporting Servlet Api 4 … jetty-issue-4578
I shipped a new version yesterday that splits out Java 7 and Java 8+ JARs.
The Java 8+ JAR has the latest Jetty version (and therefore servlet API) so this might already be fixed.
Suggest you try the
wiremock-jre8
artifact in your dependencies and see how you get on.