非启动应用程序上的Spring Boot Actuator - 更改端点basepath

时间:2018-02-09 17:13:02

标签: java spring actuator

我们开发了一个基于Spring(4.1.1)的Web应用程序,我正在尝试集成Actuator以获得一些不错的信息。

我们的筹码: Spring 4.1.1

它是一个非启动应用程序,因此在阅读了很多问题和文章后,我提出了以下代码:

的pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-actuator</artifactId>
    <version>1.1.12.RELEASE</version>
</dependency>

ActuatorConfig.java

@Configuration
@Import(EndpointAutoConfiguration.class)
public class ActuatorConfig {


    @Bean
    @Autowired
    public ManagementServerProperties myManagementServerProperties() {
        ManagementServerProperties manag = new ManagementServerProperties();
        manag.setContextPath("/actuator");

        return manag;
    }

    @Bean
    @Autowired
    // Define the HandlerMapping similar to RequestHandlerMapping to expose the
    @DependsOn("myManagementServerProperties")
    public EndpointHandlerMapping endpointHandlerMapping(Collection<? extends MvcEndpoint> endpoints) {
        return new EndpointHandlerMapping(endpoints);
    }

    @Bean
    @Autowired
    // define the HealthPoint endpoint
    @DependsOn("myManagementServerProperties")
    public HealthMvcEndpoint healthMvcEndpoint(HealthEndpoint delegate) {
        return new HealthMvcEndpoint(delegate);
    }

    @Bean
    @Autowired
    // define the Info endpoint
    @DependsOn("myManagementServerProperties")
    public EndpointMvcAdapter infoMvcEndPoint(InfoEndpoint delegate) {
        return new EndpointMvcAdapter(delegate);
    }

    @Bean
    @Autowired
    // define the beans endpoint
    @DependsOn("myManagementServerProperties")
    public EndpointMvcAdapter beansEndPoint(BeansEndpoint delegate) {
        return new EndpointMvcAdapter(delegate);
    }

    @Bean
    @Autowired
    // define the mappings endpoint
    @DependsOn("myManagementServerProperties")
    public EndpointMvcAdapter requestMappingEndPoint(RequestMappingEndpoint delegate) {
        return new EndpointMvcAdapter(delegate);
    }

    @Bean
    @Autowired
    // define the HealthPoint endpoint
    @DependsOn("myManagementServerProperties")
    public EndpointMvcAdapter dumpMvcEndpoint(DumpEndpoint delegate) {
        return new EndpointMvcAdapter(delegate);
    }

    @Bean
    @Autowired
    // define the MetricsEndpoint endpoint
    @DependsOn("myManagementServerProperties")
    public MetricsMvcEndpoint metricsMvcEndpoint(MetricsEndpoint delegate) {
        return new MetricsMvcEndpoint(delegate);
    }

    @Bean
    @Autowired
    @DependsOn("myManagementServerProperties")
    public EnvironmentMvcEndpoint environmentMvcEndpoint(EnvironmentEndpoint delegate) {
        return new EnvironmentMvcEndpoint(delegate);
    }

使用这种配置,我实际上可以调用我声明的那些端点:

2018-02-09 12:33:47,083 [localhost-startStop-1] INFO  org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/dump],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2018-02-09 12:33:47,084 [localhost-startStop-1] INFO  org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/metrics/{name:.*}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2018-02-09 12:33:47,084 [localhost-startStop-1] INFO  org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/metrics],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2018-02-09 12:33:47,084 [localhost-startStop-1] INFO  org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/beans],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2018-02-09 12:33:47,084 [localhost-startStop-1] INFO  org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/health],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke()
2018-02-09 12:33:47,084 [localhost-startStop-1] INFO  org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/info],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2018-02-09 12:33:47,084 [localhost-startStop-1] INFO  org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/mappings],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2018-02-09 12:33:47,085 [localhost-startStop-1] INFO  org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/env/{name:.*}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2018-02-09 12:33:47,085 [localhost-startStop-1] INFO  org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping - Mapped "{[/env],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

我想要实现的是将所有这些端点的基本路径更改为 \ actuator ,以便我可以调用:

https://mydomain:8443/myapp/api/actuator/dump
https://mydomain:8443/myapp/api/actuator/metrics

我在线查看后尝试了,因为它是一个非启动应用程序,正在添加此配置广告我的ActuatorConfig类:

@Bean
        @Autowired
        public ManagementServerProperties myManagementServerProperties() {
            ManagementServerProperties manag = new ManagementServerProperties();
            manag.setContextPath("/actuator");

            return manag;
        }

我尝试使用@DependsOn注释来确保myManagementServerProperties在Actuator端点之前被实例化,但没有任何改变。

我做错了什么?

0 个答案:

没有答案