java—为什么其他端点除了spring引导执行器中的信息和运行状况之外都不公开

6kkfgxo0  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(381)

我有一个springmvc应用程序,我正在尝试为性能指标和其他端点添加spring引导执行器。我没有得到指标,豆豆端点以外的信息和健康端点。有没有人能帮我找到那些端点的配置?Spring版本:5.2.8。释放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、缓存等?

eyh26e7m

eyh26e7m1#

info,health 是spring boot actuator的默认端点。
暴露终结点

似乎您没有在服务器上声明终结点 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

相关问题