简体   繁体   English

用于 Spring MVC 的 Spring Boot Actuator,无需在另一个端口上启动 Spring

[英]Spring Boot Actuator for Spring MVC without Spring boot on another port

I want to set up the spring boot actuator for the spring MVC.我想为 spring MVC 设置 spring boot 执行器。 And everything seems to be fine, but I need to output the actuator on a different port, which I can't do.一切似乎都很好,但我需要在不同的端口上输出执行器,这是我做不到的。 Maybe someone came across this?也许有人遇到过这个?

Dependencies:依赖项:

 org.springframework:spring-webmvc: 4.3.9.RELEASE

 group: 'org.springframework.boot', name: 'spring-boot-actuator', version: '1.5.4.RELEASE'

 group: 'org.apache.tomcat', name: 'tomcat-catalina', version: '8.5.15

Configurations:配置:

@Configuration
@EnableAutoConfiguration(exclude = {
        DataSourceAutoConfiguration.class,
        FreeMarkerAutoConfiguration.class,
        WebMvcAutoConfiguration.class
})
@ManagementContextConfiguration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {

. .

@Configuration
@Import({
        EndpointAutoConfiguration.class,
        EndpointWebMvcAutoConfiguration.class
})
public class ActuatorConfig {

    private final int SERVER_PORT = 9091;

    @Bean
    public EmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() {
        return new TomcatEmbeddedServletContainerFactory("/actuator", SERVER_PORT);
    }

    @Bean
    public ManagementServerProperties managementServerProperties() {
        ManagementServerProperties managementServerProperties = new ManagementServerProperties();
        managementServerProperties.setPort(SERVER_PORT);
        return managementServerProperties;
    }
}

This code displays metrics, but i can not run metrics on another port.I also suspect this is due to the EmbeddedWebApplicationContext.class , but I do not quite understand how to configure it and get the server to start此代码显示指标,但我无法在另一个端口上运行指标。我也怀疑这是由于EmbeddedWebApplicationContext.class ,但我不太明白如何配置它并使服务器启动

您可以将以下内容添加到您的 application.properties 文件中,

management.port=your_port  //eg: 8085

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM