为什么在 spring 引导执行器中除了信息和健康之外其他端点不暴露
Why other ends point not exposing except info and health in spring boot actuator
我有一个 spring-mvc 应用程序,我正在尝试为性能指标和其他端点添加 spring 启动执行器。除了信息和健康端点之外,我没有获得指标、bean 端点。任何人都可以在我错过配置以获取这些端点的地方帮助我吗?
Spring 版本:5.2。8.RELEASE Spring 引导执行器版本:2.4.2
下面是我的代码:
@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 () -> "/";
}
}
默认执行器端点url和响应:
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}}}
我应该如何获取其他端点,例如:指标、bean、缓存等?
info,health
是 spring 引导执行器的默认端点。
您似乎没有在 application.properties
上声明端点。如果是这样,请通过添加以下内容重试:
// Enable everything with wildcard
management.endpoints.web.exposure.include=*
// You can also disable some of them
management.endpoints.web.exposure.exclude=jolokia,liquibase
我有一个 spring-mvc 应用程序,我正在尝试为性能指标和其他端点添加 spring 启动执行器。除了信息和健康端点之外,我没有获得指标、bean 端点。任何人都可以在我错过配置以获取这些端点的地方帮助我吗? Spring 版本:5.2。8.RELEASE Spring 引导执行器版本:2.4.2 下面是我的代码:
@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 () -> "/";
}
}
默认执行器端点url和响应:
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}}}
我应该如何获取其他端点,例如:指标、bean、缓存等?
info,health
是 spring 引导执行器的默认端点。
您似乎没有在 application.properties
上声明端点。如果是这样,请通过添加以下内容重试:
// Enable everything with wildcard
management.endpoints.web.exposure.include=*
// You can also disable some of them
management.endpoints.web.exposure.exclude=jolokia,liquibase