我想将
/META-INF/build-info.properties
中的构建属性用作普通 Spring 属性,这样我就可以在 Logback 配置中的 via spring-property
中使用它们 logback-spring.xml
。
我已经能够使用它们了,但是有些事情发生了变化......
/META-INF/build-info.properties
在那里。BuildProperties
作为具有正确值的 bean 获取。有人知道如何像我的
logback-spring.xml
中的普通 Spring 属性一样使用构建属性吗?
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<springProperty scope="context" name="application" source="build.name"/>
<springProperty scope="context" name="version" source="build.version"/>
在 Spring Boot 应用程序中,确保 build-info.properties 文件作为属性源加载。这可以通过将以下条目添加到您的 application.properties 来完成
spring.config.name=application,build-info
spring.config.location=classpath:/,classpath:/META-INF/
将构建属性作为普通 Spring 属性加载后,您可以通过使用 ${propertyKey} 语法引用它们来在 logback-spring.xml 配置文件中使用它们。
就像例子-:
<configuration>
<property resource="META-INF/build-info.properties" />
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!-- Use the build property in the appender configuration -->
<encoder pattern="${build.version} - %msg%n" />
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
在此示例中,从 build-info.properties 文件访问 ${build.version} 属性并在配置中使用。
旧线程,但我只想留下答案以供记录。在 application.properties 中配置
spring.config.location
和 spring.config.name
can 不起作用。我的意思是...想想看...无论如何:解决方案是在 spring.config.import
中提供额外的文件,如下所示:
spring.config.import=classpath:git.properties,classpath:META-INF/build-info.properties