没有从外部jar调用@ControllerAdvice

时间:2019-02-06 14:55:51

标签: java maven spring-boot intellij-idea jar

我有一个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);
    }

0 个答案:

没有答案