我想@ControllerAdvice
为所有控制器上的所有 HTTP 请求调用一个。不幸的是,它仅在请求中有 HTTP 正文时才会触发。如果不是,则完全忽略。handleEmptyBody()
在这种情况下,春天不应该打电话吗?
编辑
所有控制器都带有注释@RestController
。
有任何想法吗?
@ControllerAdvice
public class CatchAllRequestsAdvice implements RequestBodyAdvice {
private static final Logger LOGGER = LoggerFactory.getLogger(CatchAllRequestsAdvice.class);
@Override
public boolean supports(
MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType
) {
LOGGER.info("");
return true;
}
@Override
public HttpInputMessage beforeBodyRead(
HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType
) throws IOException {
LOGGER.info("");
return inputMessage;
}
@Override
public Object afterBodyRead(
Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType
) {
LOGGER.info("");
return body;
}
@Override
public Object handleEmptyBody(
Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType
) {
LOGGER.info("");
return body;
}
}