首页 > 解决方案 > application.properties & application.yml 中相同属性的优先顺序

问题描述

我有一个使用 application.yml 文件存储属性的 spring boot (2.3.4.RELEASE) 应用程序 -

management:
  endpoints:
    enabled-by-default: true
    web.exposure.include: "*"
  endpointmetrics:
    enabled: true

该应用程序在包含 application.properties 文件的类路径上还有一个 3rd 方依赖项 jar。该文件包含(注意运行状况检查端点) -

management.endpoints.web.exposure.include=*
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=healthcheck

在运行应用程序时,默认执行器健康检查端点 /actuator/health 返回未找到并且 /healthcheck 端点工作正常。

但是,如果我将 application.yml 文件转换为 application.properties 格式 -

management.endpoints.enabled-by-default=true
management.endpoints.web.exposure.include=*
management.endpointmetrics.enabled=true

然后默认执行器健康检查端点 /actuator/health 工作,/healthcheck 端点返回 404。

我有2个问题-

  1. 为什么我的 application.properties 文件优先于 3rd 方 jar 中的 application.properties 文件而不是我的 application.yml 文件?
  2. 我想在我的应用程序中使用 application.yml 格式并忽略第 3 方 jar 中的 application.properties 文件。有可能这样做吗?

标签: spring-bootspring-boot-actuator

解决方案


推荐阅读