복붙노트

[SPRING] 스프링 부트 비활성화 / 오류 매핑

SPRING

스프링 부트 비활성화 / 오류 매핑

나는 봄 부팅으로 API를 만들어서 / 오류 매핑을 비활성화하고자합니다.

application.properties에 다음 소품을 설정했습니다.

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

그러나 내가 실수를 칠 때 :

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

해결법

  1. ==============================

    1.ErrorMvcAutoConfiguration을 비활성화 할 수 있습니다.

    ErrorMvcAutoConfiguration을 비활성화 할 수 있습니다.

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

    또는 Spring Boot의 application.yml / properties를 통해 :

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

    이것이 옵션이 아니라면, Spring의 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. ==============================

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

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

    또한 도움이 될 수있는 내 WebSecurityConfigurerAdapter 구현에서 위의 오류 json을 표시하는 대신 로그인 시도에서 구성 (WebSecurity 웹)의 본문을 주석 처리했습니다. 브라우저의 주소 표시 줄에 문제의 원인이되는 리소스가있는 URL이 표시됩니다. .

  3. from https://stackoverflow.com/questions/38747548/spring-boot-disable-error-mapping by cc-by-sa and MIT license