Jersey returns 404 with any error status code?

后端 未结 2 909
猫巷女王i
猫巷女王i 2020-11-27 08:09

I have this useless endpoint in path \"/test\":

@PUT
public Response doSomething() {
  return Response.status(409).build();
}

and I test it

相关标签:
2条回答
  • 2020-11-27 08:37

    I had this problem as well, and solved it by excluding ErrorMvcAutoConfiguration from the spring boot auto config:

    @EnableAutoConfiguration(exclude = { ErrorMvcAutoConfiguration.class })
    
    0 讨论(0)
  • 2020-11-27 08:38

    The default behavior with Jersey, when there is an error status (4xx, 5xx), is to use the servlet's Response.sendError, which results in a redirect to an error page. Since there is no error page set up, it results in a 404.

    We can change this behavior by setting the Jersey property

    ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR

    You can do this in your ResourceConfig subclass

    public JerseyConfig extends ResourceConfig {
        public JerseyConfig() {
            property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, true);
        }
    }
    

    Or (with Spring Boot) you can add it in your application.properties file.

    spring.jersey.init.jersey.config.server.response.setStatusOverSendError=true
    
    0 讨论(0)
提交回复
热议问题