Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actuator 2.X without Spring Boot

Following some links I tried to setup actuator 2.X without Spring Boot, but no help.

Tried with /health, /application/health, /actuator/health but none worked. I earlier used Actuator 1.X and just by adding EndpointWebMvcManagementContextConfiguration, EndpointAutoConfiguration, PublicMetricsAutoConfiguration and HealthIndicatorAutoConfiguration to my xml context and pom dependencies, it worked smoothly.

Now my requirement is to add/remove health indicators on the fly, so need to move on to Actuator 2.X.

like image 784
pankaj_ar Avatar asked Jun 08 '26 05:06

pankaj_ar


1 Answers

I've been fiddling recently with including Spring Actuator 2.x to an existing Spring MVC project. This is a configuration which worked

@Configuration
@Import({
        EndpointAutoConfiguration.class,
        HealthIndicatorAutoConfiguration.class,

        InfoEndpointAutoConfiguration.class,
        HealthEndpointAutoConfiguration.class,

        WebEndpointAutoConfiguration.class,
        ServletManagementContextAutoConfiguration.class,
        ManagementContextAutoConfiguration.class,
})
@EnableConfigurationProperties(CorsEndpointProperties.class)
class ActuatorConfiguration {

    @Bean //taken from WebMvcEndpointManagementContextConfiguration.class
    public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier,
                                                                         ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier,
                                                                         EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties,
                                                                         WebEndpointProperties webEndpointProperties) {
        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());
        return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
                corsProperties.toCorsConfiguration(),
                new EndpointLinksResolver(allEndpoints, webEndpointProperties.getBasePath()));
    }

    @Bean
    DispatcherServletPath dispatcherServletPath() {
        return () -> "/";
    }

}

I did include

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-actuator-autoconfigure</artifactId>
        <version>2.1.18.RELEASE</version>
    </dependency>

for compatibility with the baseline Spring version I've been using (5.1.19.RELEASE)

The actuator endpoints are exposed with /actuator/*

like image 142
Jakub Marchwicki Avatar answered Jun 10 '26 20:06

Jakub Marchwicki