본문 바로가기
일이야기/Spring

BasicErrorController.error Ambiguous 처리

by Cloud9™ 2019. 9. 18.

 

2019/09/18 - [일이야기/Spring] - Tomcat 구동시 ErrorPageFilter 에러 처리

 

Tomcat 구동시 ErrorPageFilter 에러 처리

기본적으로 Spring boot에서는 에러를 처리하는 filter가 자동으로 동작한다. 하지만 프로젝트에 따라 Application내에서 에러 핸들링을 달리해야 하는데 Filter에서 선처리하고 아래와 같은 에러 로그를 출력한다..

naning9.tistory.com

이전 글에서 ErrorPageFilter를 disabled하고 Application 내에서 에러페이지를 분기하려고 

GlobalErrorController를 만들었는데 아래와 같은 에러가 발생했다.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'basicErrorController' method public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest) to { /error}: There is already 'globalErrorController' bean method

내용을 보면 어쩌구 저쩌구....BasicErrorController.error 에 /error 라는 경로가 이미 있다라고 하네..

 

BasicErrorController를 사용하지 못하도록 처리해 보자.

 

Java Config 

@Configuration
@EnableAutoConfiguration(exclude = ErrorMvcAutoConfiguration.class)
public class ErrorConfiguration {
....
}

또는

Application.yml

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

댓글