Skip to content

Instantly share code, notes, and snippets.

@caoxudong
Created December 28, 2019 11:42
Show Gist options
  • Save caoxudong/bb13233818729e49ec80373cbea6b851 to your computer and use it in GitHub Desktop.
Save caoxudong/bb13233818729e49ec80373cbea6b851 to your computer and use it in GitHub Desktop.
intercept actuator uri in springboot 2
package demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.servlet.WebMvcEndpointManagementContextConfiguration;
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ActuatorConfig
extends WebMvcEndpointManagementContextConfiguration {
@Autowired
private MyInterceptor myInterceptor;
@Override
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
WebEndpointsSupplier webEndpointsSupplier,
ServletEndpointsSupplier servletEndpointsSupplier,
ControllerEndpointsSupplier controllerEndpointsSupplier,
EndpointMediaTypes endpointMediaTypes,
CorsEndpointProperties corsProperties,
WebEndpointProperties webEndpointProperties) {
WebMvcEndpointHandlerMapping mapping =
super.webEndpointServletHandlerMapping(webEndpointsSupplier,
servletEndpointsSupplier, controllerEndpointsSupplier,
endpointMediaTypes, corsProperties,
webEndpointProperties);
mapping.setInterceptors(myInterceptor);
return mapping;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment