【问题标题】:Spring Boot with Actuator .war deployed on tomcat在 tomcat 上部署带有 Actuator .war 的 Spring Boot
【发布时间】:2016-11-26 10:18:55
【问题描述】:

我在 Spring Boot 中配置了执行器,基本上一切正常,直到我在 tomcat 容器上部署文件。

为了使执行器工作,我需要创建额外的配置类:

@Configuration
@Import({ EndpointAutoConfiguration.class, PublicMetricsAutoConfiguration.class,
    HealthIndicatorAutoConfiguration.class }) public class SpringBootActuatorConfig { beans...} 

这工作正常 - 但它不是使用配置,我在配置 (application.properties) 文件中,例如:

management.contextPath=/服务器

endpoints.health.path=/ping/me

但是执行器仍然给我没有“/服务器”路径的端点。

我尝试添加:

@PropertySource("classpath:/config/application.properties")

找到属性文件,但这不会更改执行器配置。

在这种情况下设置执行器配置的正确方法是什么?

【问题讨论】:

  • 部署war文件时不能更改contextPath,斜纹布只适用于嵌入式容器。它也应该只用于检测自动配置,你不能改变contextPath
  • 好的。那么如何为所有执行器端点设置上下文路径?

标签: tomcat configuration spring-boot spring-boot-actuator


【解决方案1】:

Spring Boot Application Properties

向下滚动到MANAGEMENT HTTP SERVER 部分,您将在其中找到此路径属性:

management.context-path= # Management endpoint context-path. For instance `/actuator`

此上下文路径会影响标准管理端点,例如 /beans、/env、/health 等。

在页面下方,您还会看到 ACTUATOR PROPERTIES 部分,其中包含其他执行器端点的配置属性。

Full Sample Project

【讨论】:

  • 它不工作。看起来 application.properties 文件中的属性未加载(用于执行器)
  • @user1055201 你能在 GitHub 上分享一个完整的示例项目吗?我敢打赌你的配置有问题。
  • @user1055201 我已更新我的答案以提供更多说明和完整的示例项目。
  • 我已经有了这个属性设置:management.context-path=/server :) 你能看到 github 项目吗?
  • @user1055201 是的,但是您的示例很复杂。示例项目应该是最小的、完整的和可验证的。看到这个:stackoverflow.com/help/mcve
【解决方案2】:

我也遇到了这个问题,我的解决方法是

@Bean
public EndpointHandlerMapping endpointHandlerMapping(Collection<? extends MvcEndpoint> endpoints) {
    EndpointHandlerMapping endpointHandlerMapping = new EndpointHandlerMapping(endpoints);
    endpointHandlerMapping.setPrefix("/manage");
    return endpointHandlerMapping;
}

【讨论】:

    猜你喜欢
    • 2016-08-11
    • 2015-09-03
    • 2015-03-10
    • 2018-12-05
    • 1970-01-01
    • 2020-10-23
    • 2020-06-17
    • 2018-05-18
    • 1970-01-01
    相关资源
    最近更新 更多