在類路徑 application.property 上有 log4j2 和 spring 屬性檔案的標準配置。
log4j2.xml
<Properties>
...
<Property name="APP_LOG_ROOT">${bundle:application:log.root.dir}</Property>
...
</Properties>
應用程式屬性
...
log.root.dir=/opt/tomcat/logs
...
資料被正確讀入log4j2.xml,但是如果我想在使用maven創建工件并放置不同的application.property時獲得替代屬性怎么辦:
mvn clean install -Dapplication.properties.path=file:/some_path/application.properties
? 之后,我可以正確讀取新屬性。
@Value("${log.root.dir}")
private String ololo;
但是 log4j2 不能自己做到這一點。
uj5u.com熱心網友回復:
如果要在 Log4j2 組態檔中使用Spring 的任何值Environment,則需要使用Spring Boot Lookup。
添加log4j-spring-boot到類路徑后,您只需要替換
${bundle:application:log.root.dir}
和
${spring:log.root.dir}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/493905.html
上一篇:WriteProcessMemory,同時程式的值 用戶的輸入值
下一篇:org.springframework.dao.IncorrectResultSizeDataAccessExceptionMongoLimit不起作用?
