2016-08-03 6 views
7

스프링 부트로 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 

답변

15

당신이 할 수있는 ErrorMvcAutoConfiguration을 비활성화하십시오.

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

이, 당신은 또한 자신의 구현과 봄의 ErrorController을 연장 할 수있다 당신을위한 옵션이없는 경우 :

@RestController 
public class MyErrorController implements ErrorController { 

    private static final String ERROR_MAPPING = "/error"; 

    @RequestMapping(value = ERROR_MAPPING) 
    public ResponseEntity<String> error() { 
     return new ResponseEntity<String>(HttpStatus.NOT_FOUND); 
    } 

    @Override 
    public String getErrorPath() { 
     return ERROR_MAPPING; 
    } 
+2

그래,이게 정확히 성가시다. 궁금해 할 일이없는 바인딩을 제거하는 방법이 있다면 – ptimson

+0

같은 오류, 내가 모든 오류를 이제는 json 대신 html로 ... – TheBakker

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

또는 봄 부팅의 application.yml/속성을 통해

제 경우에는 로그인 페이지의 헤더에서 참조되는 웹 리소스에 문제가있었습니다. 특히 CSS는 헤더에서 참조되었지만 실제로 프로젝트에는 존재하지 않았습니다.

WebSecurityConfigurerAdapter 구현에서 도움이 될 수도있는 것은 무엇보다도 먼저 configure(WebSecurity web)의 본문을 주석 처리 한 다음 위의 오류 json을 표시하는 대신 로그인하려고 시도하는 대신 브라우저의 주소 표시 줄에 문제를 일으키는 URL이 표시됩니다 .