簡體   English   中英

用於 Spring MVC 的 Spring Boot Actuator,無需在另一個端口上啟動 Spring

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

我想為 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 ,但我不太明白如何配置它並使服務器啟動

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

management.port=your_port  //eg: 8085

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM