在某些链接下,我尝试在没有Spring Boot的情况下设置执行器2.X,但没有帮助。
尝试了/health
,/application/health
,/actuator/health
,但没有一个有效。我以前使用过Actuator 1.X,只是将EndpointWebMvcManagementContextConfiguration
,EndpointAutoConfiguration
,PublicMetricsAutoConfiguration
和HealthIndicatorAutoConfiguration
添加到我的xml上下文和pom依赖项中,就可以正常工作。
现在,我的要求是即时添加/删除健康指标,因此需要继续使用Actuator 2.X。
答案 0 :(得分:0)
在Spring Boot 2.x中,端点已更改。你可以参考这个 Exposing Endpoints 详细的迁移指南在此处detailed migration guide
要更改公开哪些端点,请使用以下特定于技术的包含和排除属性:
application.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},
..................
...........
...................
}}}
答案 1 :(得分:0)
我最近一直忙于将 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/*