Как использовать компоненты пользовательского фляги в другом проекте - PullRequest
0 голосов
/ 08 мая 2019

Я создал jar для пользовательского обработчика исключений с помощью @ControllerAdvice в springboot и использовал этот jar в другом проекте с использованием репозитория maven.Когда в проекте возникает исключение, оно не обрабатывается этим классом обработчика исключений jar.

Если я использовал @ComponentScan ("com.test. *") В конфигурации, выдает ошибку:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'globalExceptionHandler': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.test.GlobaExceptionHandler] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

Мой файл JAR содержит класс:


@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
// handle application/json content-type missing
    @Override
    protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex,
                                                                     HttpHeaders headers, HttpStatus status,
                                                                     WebRequest request) {

        logger.error("<<< handleHttpMediaTypeNotSupported : "+ ex + " url: "+request.getDescription(false));

        String unsupported = "Unsupported content type: " + ex.getContentType();
        String supported = "Supported content types: " + MediaType.toString(ex.getSupportedMediaTypes());

        String url = request.getDescription(false);
        ExceptionResponse exceptionResponse = new ExceptionResponse(unsupported, supported, url);
        globalResponse = new GlobalResponseDto(HttpStatus.METHOD_NOT_ALLOWED.value(), HttpStatus.METHOD_NOT_ALLOWED,
                new Date(), errorStatus, null, exceptionResponse);

        return new ResponseEntity<Object>(globalResponse, new HttpHeaders(), HttpStatus.METHOD_NOT_ALLOWED);
    }
...
// some other exception handlers...
}


Then i used the jar in pom.xml in another springboot project. How to make exception to handle from this class when exception occurs in @RestController class.

Thank you all in advance.
...