Jersey returns 404 with any error status code?

孤街浪徒 提交于 2019-11-26 19:11:28

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

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

@EnableAutoConfiguration(exclude = { ErrorMvcAutoConfiguration.class })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!