简体   繁体   English

不带 Spring Boot 的 Actuator 2.X

[英]Actuator 2.X without Spring Boot

Following some links I tried to setup actuator 2.X without Spring Boot, but no help.通过一些链接,我尝试在没有 Spring Boot 的情况下设置 actuator 2.X,但没有帮助。

Tried with /health , /application/health , /actuator/health but none worked.尝试过/health/application/health/actuator/health但都没有用。 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.我之前使用了 Actuator 1.X,只需将EndpointWebMvcManagementContextConfigurationEndpointAutoConfigurationPublicMetricsAutoConfigurationHealthIndicatorAutoConfiguration添加到我的 xml 上下文和 pom 依赖项中,它就可以顺利运行。

Now my requirement is to add/remove health indicators on the fly, so need to move on to Actuator 2.X.现在我的要求是动态添加/删除健康指标,因此需要继续使用 Actuator 2.X。

I've been fiddling recently with including Spring Actuator 2.x to an existing Spring MVC project.我最近一直在尝试将 Spring Actuator 2.x 包含到现有的 Spring MVC 项目中。 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)为了与我一直使用的基准 Spring 版本 (5.1.19.RELEASE) 兼容

The actuator endpoints are exposed with /actuator/*执行器端点通过/actuator/*公开

In spring Boot 2.x, the endpoints has been changed.在 spring Boot 2.x 中,端点已更改。 You can refer this Exposing Endpoints The detailed migration guide is here detailed migration guide您可以参考这个Exposing Endpoints详细的迁移指南在这里详细的迁移指南

To change which endpoints are exposed, use the following technology-specific include and exclude properties:要更改公开的端点,请使用以下特定于技术的包含和排除属性:

application.properties应用程序.properties

management.endpoints.web.exposure.include=*

Output输出

      {"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false},"auditevents":{"href":"http://localhost:8080/actuator/auditevents","templated":false},"beans":{"href":"http://localhost:8080/actuator/beans","templated":false},"caches-cache":{"href":"http://localhost:8080/actuator/caches/{cache}","templated":true},"caches":{"href":"http://localhost:8080/actuator/caches","templated":false},
..................
...........
...................
}}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM