I have a spring-mvc application where I am trying to add spring boot actuator for performance metrics and other endpoints. I am not getting metrics, beans endpoint other than info and health endpoint. Can anyone please help me where I'm missed the configuration to get those endpoint? Spring version : 5.2.8.RELEASE Spring Boot actuator version : 2.4.2 Below is my code :
@Configuration
@EnableWebMvc
@Import({
ConfigurationPropertiesReportEndpointAutoConfiguration.class,
EndpointAutoConfiguration.class,
WebEndpointAutoConfiguration.class,
HealthEndpointAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class,
InfoEndpointAutoConfiguration.class,
InfoContributorAutoConfiguration.class,
LogFileWebEndpointAutoConfiguration.class,
LoggersEndpointAutoConfiguration.class,
BeansEndpointAutoConfiguration.class,
EnvironmentEndpointAutoConfiguration.class,
CachesEndpointAutoConfiguration.class,
AuditEventsEndpointAutoConfiguration.class,
MetricsAutoConfiguration.class,
MetricsEndpointAutoConfiguration.class,
WebMvcMetricsAutoConfiguration.class,
ManagementWebSecurityAutoConfiguration.class,
ManagementContextAutoConfiguration.class,
ServletManagementContextAutoConfiguration.class,
})
@EnableConfigurationProperties(CorsEndpointProperties.class)
public class ActuatorConfiguration2 {
@Bean //taken from WebMvcEndpointManagementContextConfiguration.class
public WebMvcEndpointHandlerMapping endpointHandlerMapping(WebEndpointsSupplier webEndpointsSupplier,
ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier
controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties
corsProperties, WebEndpointProperties webEndpointProperties,Environment environment) {
List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
allEndpoints.addAll(webEndpoints);
allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
//EndpointMapping endpointMapping = new EndpointMapping(webEndpointProperties.getBasePath());
String basePath = webEndpointProperties.getBasePath();
EndpointMapping endpointMapping = new EndpointMapping(basePath);
boolean shouldRegisterLinksMapping = StringUtils.hasText(basePath) ||
ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT);
return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
corsProperties.toCorsConfiguration(),
new EndpointLinksResolver(allEndpoints, webEndpointProperties.getBasePath()),
shouldRegisterLinksMapping);
}
@Bean
public DispatcherServletPath dispatcherServletPath(){
return () -> "/";
}
}
Default actuator endpoint url and response :
http://localhost:8090/com.springmvc.actuator.demo3/actuator/
{"_links":{"self":{"href":"http://localhost:8090/com.springmvc.actuator.demo3/actuator","templated":false},"health":{"href":"http://localhost:8090/com.springmvc.actuator.demo3/actuator/health","templated":false},"health-path":{"href":"http://localhost:8090/com.springmvc.actuator.demo3/actuator/health/{*path}","templated":true},"info":{"href":"http://localhost:8090/com.springmvc.actuator.demo3/actuator/info","templated":false}}}
what should i do for getting the other endpoints like : metrics, beans, caches etc?
info,health
are the default endpoints for spring boot actuator.
It seems that you did not declare endpoints on your application.properties
. If so, pls try again by adding following:
// Enable everything with wildcard
management.endpoints.web.exposure.include=*
// You can also disable some of them
management.endpoints.web.exposure.exclude=jolokia,liquibase