Using Expressions in Spring application.properties file

前端 未结 3 2149
梦毁少年i
梦毁少年i 2020-12-06 18:32

Can expressions be used as a right-hand-side value in a Spring application.properties file?

For example, something like this:

logging.level.com.acme=         


        
3条回答
  •  無奈伤痛
    2020-12-06 18:59

    No you can not use SpEL within properties files.

    Finally, while you can write a SpEL expression in @Value, such expressions are not processed from Application property files.

    You can however use placeholders within properties files, eg:

    app.name=MyApp
    app.description=${app.name} is a Spring Boot application
    

    For your use case, you should look at the profile-specific configuration mechanism.

    Which allows you to load different config based on an environment profile.

提交回复
热议问题