![](/img/trans.png)
[英]How migrate an actuator that extends AbstractMvcEndpoint to Spring Boot 2.x?
[英]Actuator 2.X without Spring Boot
通過一些鏈接,我嘗試在沒有 Spring Boot 的情況下設置 actuator 2.X,但沒有幫助。
嘗試過/health
、 /application/health
、 /actuator/health
但都沒有用。 我之前使用了 Actuator 1.X,只需將EndpointWebMvcManagementContextConfiguration
、 EndpointAutoConfiguration
、 PublicMetricsAutoConfiguration
和HealthIndicatorAutoConfiguration
添加到我的 xml 上下文和 pom 依賴項中,它就可以順利運行。
現在我的要求是動態添加/刪除健康指標,因此需要繼續使用 Actuator 2.X。
我最近一直在嘗試將 Spring Actuator 2.x 包含到現有的 Spring MVC 項目中。 這是一個有效的配置
@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 () -> "/";
}
}
我確實包括
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<version>2.1.18.RELEASE</version>
</dependency>
為了與我一直使用的基准 Spring 版本 (5.1.19.RELEASE) 兼容
執行器端點通過/actuator/*
公開
在 spring Boot 2.x 中,端點已更改。 您可以參考這個Exposing Endpoints詳細的遷移指南在這里詳細的遷移指南
要更改公開的端點,請使用以下特定於技術的包含和排除屬性:
應用程序.properties
management.endpoints.web.exposure.include=*
輸出
{"_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.