I’m migrating Spring Boot microservice from version 2021.0.9 to 2023.0.1. I have one microservice with shared library for handling exceptions.
Spring Boot microservice:
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
@ControllerAdvice
@Order(Integer.MAX_VALUE)
public class CommonControllerAdvice extends ResponseEntityExceptionHandler {
private static final String LABEL = "Label";
@ExceptionHandler(Exception.class)
public final ResponseEntity<Object> handleHystrixBadRequestException(
.........
return null;
}
}
Shared library:
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
@ControllerAdvice
@Order(Integer.MAX_VALUE)
public class CommonControllerAdvice extends ResponseEntityExceptionHandler {
@ExceptionHandler(Exception.class)
public final ResponseEntity<Object> handleException(Exception ex) {
......
return ....;
}
}
Error during boot time:
Error creating bean with name 'handlerExceptionResolver' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Failed to instantiate [org.springframework.web.servlet.HandlerExceptionResolver]: Factory method 'handlerExceptionResolver' threw exception with message: Ambiguous @ExceptionHandler method mapped for [class java.lang.Exception]: {public final org.springframework.http.ResponseEntity com.atlas.mpp.transaction.search.web.rest.SearchControllerAdvice.handleHystrixBadRequestException(java.lang.Exception), public final org.springframework.http.ResponseEntity com.error.web.handlers.CommonControllerAdvice.handleException(java.lang.Exception)}
.........
Failed to instantiate [org.springframework.web.servlet.HandlerExceptionResolver]: Factory method 'handlerExceptionResolver' threw exception with message: Ambiguous @ExceptionHandler method mapped for [class java.lang.Exception]: {public final org.springframework.http.ResponseEntity com.microservice.SearchControllerAdvice.handleHystrixBadRequestException(java.lang.Exception), public final org.springframework.http.ResponseEntity com.lib.web.handlers.CommonControllerAdvice.handleException(java.lang.Exception)}
.......
Ambiguous @ExceptionHandler method mapped for [class java.lang.Exception]: {public final org.springframework.http.ResponseEntity com.microservice.web.rest.SearchControllerAdvice.handleHystrixBadRequestException(java.lang.Exception), public final org.springframework.http.ResponseEntity com.lib.web.handlers.CommonControllerAdvice.handleException(java.lang.Exception)}
This code was working fine in version 2021.0.9 but in version 2023.0.1 I get the above error. Looks like there is a restructure in new version. What are the possible ways to solve this?