Spring Boot禁用/错误映射

我正在使用Spring Boot创建API,因此希望禁用/error映射。

我在application.properties中设置了以下道具:

 server.error.whitelabel.enabled=false spring.mvc.throw-exception-if-no-handler-found=true spring.resources.add-mappings=false 

但是,当我点击/error我得到:

 HTTP/1.1 500 Internal Server Error Server: Apache-Coyote/1.1 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Wed, 03 Aug 2016 15:15:31 GMT Connection: close {"timestamp":1470237331487,"status":999,"error":"None","message":"No message available"} 

要求的结果

 HTTP/1.1 404 Internal Server Error Server: Apache-Coyote/1.1 

您可以禁用ErrorMvcAutoConfiguration:

 @SpringBootApplication @EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class}) public class SpringBootLauncher { 

或者通过Spring Boot的application.yml / properties:

 spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration 

如果这不适合您,您也可以使用自己的实现扩展Spring的ErrorController:

 @RestController public class MyErrorController implements ErrorController { private static final String ERROR_MAPPING = "/error"; @RequestMapping(value = ERROR_MAPPING) public ResponseEntity error() { return new ResponseEntity(HttpStatus.NOT_FOUND); } @Override public String getErrorPath() { return ERROR_MAPPING; } 

就我而言,问题在于登录页面标题中引用的Web资源。 具体来说,标题中引用了css,但实际上并没有在项目中存在。

什么也可能有用,在我的WebSecurityConfigurerAdapter实现中我首先注释掉了configure(WebSecurity web) ,然后尝试登录,而不是显示上面的错误json我的浏览器的地址栏会显示导致问题的资源的url 。