【问题标题】:Spring Boot Actuator for Spring MVC without Spring boot on another port用于 Spring MVC 的 Spring Boot Actuator,在另一个端口上没有 Spring Boot
【发布时间】:2021-12-14 00:17:56
【问题描述】:

我想为 spring MVC 设置 spring boot 执行器。一切似乎都很好,但我需要在不同的端口上输出执行器,这是我做不到的。也许有人遇到过这个?

依赖关系:

 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

配置:

@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;
    }
}

此代码显示指标,但我无法在另一个端口上运行指标。我也怀疑这是由于EmbeddedWebApplicationContext.class,但我不太明白如何配置它并让服务器启动

【问题讨论】:

  • @PiotrP.Karwasz 如果我不使用弹簧靴,这有帮助吗?如果是,你能告诉我如何帮助 spring 找到 application.properties。无论如何,感谢您的回答。
  • “我不使用 spring boot”:你的意思是什么(你代码中的许多类和注释都来自 Spring Boot)?这是否意味着您使用外部 Tomcat 来部署应用程序,或者您是否有自定义类来启动它?
  • @PiotrP.Karwasz 是的,我使用的是 spring boot 依赖项,但是在添加 application.propertis 时,什么都没有改变
  • 但开始出现异常。 WARN EndpointWebMvcAutoConfiguration.java:159 - Could not start embedded management container on different port (management endpoints are still available through JMX)

标签: java spring spring-mvc tomcat spring-boot-actuator


【解决方案1】:

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

management.port=your_port  //eg: 8085

【讨论】:

  • 谢谢你的回答,如果我不使用spring boot,这有帮助吗?
猜你喜欢
  • 2017-10-11
  • 1970-01-01
  • 2020-09-15
  • 2020-03-25
  • 1970-01-01
  • 2018-06-17
  • 2021-08-25
  • 2016-06-01
  • 1970-01-01
相关资源
最近更新 更多