javax.servlet.http.HttpServletResponse.getStatus() not found

后端 未结 2 1374
清歌不尽
清歌不尽 2020-12-19 14:37

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,

相关标签:
2条回答
  • 2020-12-19 15:26

    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>
    
    0 讨论(0)
  • 2020-12-19 15:34

    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
    
    0 讨论(0)
提交回复
热议问题