I have a SpEL expression in my application.properties file that I'm trying to load into my logback-spring.xml file. I have printed the SpEL expression, so I know it evaluates correctly. But the logback keeps printing the SpEL instead of evaluating it.
In my prop file, I have
user.name= #{user.firstName.concat(' ').concat(user.lastName)}
And in my logback file, I have
<springProperty scope="context" name="user_name" source="user.name" />
...
<pattern>name=${user_name} %msg%n </pattern>
Instead of printing the name, it prints "name=#{user.firstName.concat(' ').concat(user.lastName)}"
I have another value loaded from my prop file (not a SpEL expression), and that one works correctly. So I know the mistake I'm making is that I'm not making the logback file evaluate the expression
Spring logback extensions which are active in a logback-spring.xml
file do not support SPEL expression evaluation. The only features supported are described here: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.logging.logback-extensions
Also, your assumption about SPEL evaluation in properties files seems to be incorrect:
SpEL expressions from application property files are not processed at time of parsing these files and populating the environment.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.