How to configure default application.properties via e.g. custom starter?

后端 未结 1 422
执笔经年
执笔经年 2021-01-03 09:21

To ease internal development I\'m thinking of developing a thin layer / customer starter for Spring Boot. This custom starter just depends on some boot starters and some oth

相关标签:
1条回答
  • 2021-01-03 09:57

    Spring Boot looks for properties using a specific order:

    1. Command line arguments
    2. Java System properties (System.getProperties())
    3. OS environment variables
    4. JNDI attributes from java:comp/env
    5. A RandomValuePropertySource that only has properties in random.*
    6. Application properties outside of your packaged jar (application.properties including YAML and profile variants)
    7. Application properties packaged inside your jar (application.properties including YAML and profile variants)
    8. @PropertySource annotations on your @Configuration classes
    9. Default properties (specified using SpringApplication.setDefaultProperties)

    To give the projects using your custom starter the most flexibility in how to override the defaults, you should use a mechanism that's as near to the end of the above list as possible. Given that you already have your own subclass of SpringApplication, I would use SpringApplication.setDefaultProperties(Properties) from within that subclass.

    0 讨论(0)
提交回复
热议问题