我正在使用Spring Boot2.2.9.RELEASE。我有主应用程序和一些普通的starter (它只使用spring-actuator功能),在它的some-starter/src/main/resources/application.properties文件中有一些属性:
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我已经将starter导入到我的主应用程序中,并且我相信healthcheck端点应该与端口9000和路径/health (smth类似于那个localhost:9000/health)一起工作。
然而,如果我的主应用程序main-app/src/main/resources/application.properties中有相同的属性,它就会起作用。
Spring Boot中的属性重写有问题吗?我是否应该通过maven-resources-plugin之类的工具配置我的资源
发布于 2020-08-08 02:33:25
当从类路径加载application.properties时,类路径上的第一个将被加载,类路径上的任何其他are都将被忽略。在本例中,main-app/src/main/resources/application.properties中的文件将出现在some-starter的jar中的application.properties之前的类路径中。
顾名思义,application.properties旨在配置您的应用程序,不应该在starter中使用它。您可以在应用程序中配置所有属性,也可以更新入门程序以包含通过spring.factories注册的EnvironmentPostProcessor,并将一些默认属性添加到Environment中。
https://stackoverflow.com/questions/63305836
复制相似问题