spring-boot - Spring Boot + Logback - 外部配置与本地配置
问题描述
我有一个带有本地 application.properties 文件的 Spring Boot 应用程序,其中包含:
logging.config=src/main/resources/local/logback-dev.xml
在这个 logback-dev.xml 文件中,有一个带有本地路径的文件附加程序(比如 /local/path/log/)
当部署到不同的环境(比如 PROD)时,部署的人使用他自己的 application.properties 文件作为外部化配置(--spring.config.location=...),其中包含:
logging.config=/prod/path/logback-prod.xml
在该 logback-prod.xml 文件中,有一个具有不同路径的文件附加程序(例如 /prod/path/log/)
运行应用程序时,出现错误,因为似乎两个文件都被利用了:我们在日志中出现 /prod/path/log/ 消息,例如“找不到路径 /local/path/log/ ”
有人可以解释这里发生了什么吗?我认为外部化配置会覆盖本地配置,但这里有些奇怪。
解决方案
我们有同样的问题,并在本文档的帮助下找到了解决方案: 外部配置 https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-配置 应用程序属性 https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-application-property-files
在 Pom 中,我们添加了:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/application.properties</exclude>
<exclude>**/application-development.properties</exclude>
<exclude>**/application-production.properties</exclude>
<exclude>**/logback.xml</exclude>
</excludes>
</configuration>
</plugin>
希望这能解决您的问题并帮助您理解。
推荐阅读
- logparser - 使用 logparser 解析特定年龄的文件
- c# - NUnit Assert.AreEqual(LeftObject,RigtObject)
- c - C - 如何在 getopts 中读取多个参数?
- python - 在 Python 中重新映射 OpenCV 中的像素值的最快方法是什么?
- error-handling - 如何使用自定义结构实现错误
- android - 显示当前用户详细信息(例如名称) - Bloc flutter
- sql - 如何格式化 TRUNC?
- spring-boot - 启用 /oauth/token 端点 springdoc-openapi-ui
- anylogic - Anylogic:发布块,没有可用的 set_resourcesGoHome() 函数
- apache-kafka - 直接将我的 Kafka 代理暴露给外部消费者还是使用基于 http 的网关?