java - How to apply HandlerInterceptor to Spring Boot Actuator endpoints? -
i'm working java 8 , spring 1.2.3 build application running inside tomcat 7 container.
i intercept every single call web application using simple handlerinterceptor
, logs overall time taken create response , return code every request.
i activated actuator endpoints adding spring-boot-starter-actuator
dependency, , add interceptor calling
@configuration @enablewebmvc public class webconfig extends webmvcconfigureradapter { @autowired private application application; @override public void addinterceptors(interceptorregistry registry) { registry.addinterceptor(application.executetimeinterceptor()); } }
apparently, endpoints managed spring boot actuator (/info
, /health
, forth) not intercepted: how can make sure interceptor intercepts , every call made application, including ones invoking actuator-provided endpoint?
you can use endpointhandlermappingcustomizer
configure interceptors of actuator's endpoints. example:
@bean public endpointhandlermappingcustomizer mappingcustomizer() { return new endpointhandlermappingcustomizer() { @override public void customize(endpointhandlermapping mapping) { mapping.setinterceptors(new object[] { application.executetimeinterceptor() }); } }; }
Comments
Post a Comment