簡體   English   中英

Spring 引導無法使用依賴的應用程序。屬性

[英]Spring Boot not working with dependent application.properties

我正在使用 Spring Boot 2.2.9.RELEASE。 我在其some-starter/src/main/resources/application.properties文件中有主應用程序和一些簡單的啟動器(僅使用spring-actuator功能)和一些屬性:

management.server.port=9000
management.server.ssl.enabled=false
management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=health

我已經將啟動器導入到我的主應用程序中,並且我相信 healthcheck 端點應該與端口9000和路徑/health一起使用(就像localhost:9000/health一樣)。

但事實並非如此。 但是,它適用於我的主應用程序main-app/src/main/resources/application.properties中的相同屬性。

Spring Boot 中的屬性覆蓋是否有問題? 我應該通過maven-resources-plugin類的東西配置我的資源嗎?

當從類路徑加載application.properties時,將加載類路徑上的第一個,而忽略類路徑上的任何其他屬性。 在您的情況下, main-app/src/main/resources/application.properties中的文件將出現在some-starter的 jar 中的application.properties之前的類路徑中。

顧名思義, application.properties旨在配置您的應用程序,不應在啟動程序中使用它。 您應該配置應用程序中的所有屬性,或者您可以更新啟動器以包含通過spring.factories注冊的EnvironmentPostProcessor並向Environment添加一些默認屬性。

暫無
暫無

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

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