I am working with an embedded Jetty server, deploying a Jersey REST api, and I am trying to log the errors, with log4J. When an error happens, for instance a URL not found,
I had the same problem while I was running tests with MockMvc. I was using javax.servlet-api
in my library, which was a dependency in my microservice. I changed scope from compile
to provided
. Now it is working.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
You have a really old servlet-api jar present in your project.
javax.servlet.http.HttpServletResponse#getStatus() was added in Servlet 3.0
Add the following:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
Dump your dependencies and verify that you don't have multiple versions of the servlet-api jars present (this is common, as the maven coordinate space for the servlet-api jars have changed a few times over the past 10 years)
$ mvn dependency:tree