Read properties by dynamic keys in spring boot

前端 未结 2 802
南旧
南旧 2020-12-09 19:24

I wanted to know if there is any way in Spring Boot to read property values from properties file by using Dynamic Keys. I know properties can be put in applic

2条回答
  •  清歌不尽
    2020-12-09 20:28

    1- Register a Properties File via Java Annotations.

    @Configuration
    @PropertySource("classpath:test.properties")
    public class PropertiesJavaConfig {
        
    }
    

    2- Dynamically select the right file at runtime.

    @PropertySource({ 
      "classpath:persistence-${envTarget:DB}.properties"
    })
    

提交回复
热议问题