我有一个Spring Boot Web应用程序,该应用程序使用包含@ControllerAdvice
的外部jar。当我运行应用程序时,没有调用任何@ExceptionHandler
方法。但是,当我从外部jar中取出类并返回到应用程序中时。一切正常。这是我在外部jar中的@ControllerAdvice
类
import org.zalando.problem.Status;
import org.zalando.problem.violations.ConstraintViolationProblem;
@ControllerAdvice
public class ExceptionTranslator implements ProblemHandlingWithNoSecurity {
private static final String VIOLATIONS = "violations";
private static final String MESSAGE = "message";
public static final String ERROR_HTTP = "error.http.";
public ExceptionTranslator() {
}
@ExceptionHandler
public ResponseEntity<Problem> handleBadRequestAlertException(BadRequestAlertException ex, NativeWebRequest request) {
return this.create(ex, request, HeaderUtil.createFailureAlert(ex.getApplicationName(), ex.getEntityName(), ex.getErrorKey(), ex.getMessage()));
}
@ExceptionHandler
public ResponseEntity<Problem> handleConcurrencyFailure(ConcurrencyFailureException ex, NativeWebRequest request) {
Problem problem = Problem.builder().withStatus(Status.CONFLICT).with("message", "error.concurrencyFailure").build();
return this.create(ex, problem, request);
}