What is the order of precedence when there are multiple Spring's environment profiles as set by spring.profiles.active

前端 未结 3 1137
悲哀的现实
悲哀的现实 2020-12-08 09:32

I am just wondering what the order of precedence is when multiple Spring active profiles have been specified.

Say I want the default pr

3条回答
  •  执念已碎
    2020-12-08 10:11

    The last definition wins. I keep it in mind but:

    It is very important to remember that if you have some default content of application.properties inside jar resources, then this resource content will overwrite entries from external content of less important profiles (other profiles defined earlier in spring.profiles.active).

    Example profiles: spring.profiles.active=p1,p2,p3

    Files in Jar resources: application-p1.properties and application-p3.properties

    External files: application-p1.properties and application-p2.properties

    Final order will be (last wins):

    1. resource application.properties
    2. external application.properties
    3. resource application-p1.properties
    4. external application-p1.properties
    5. external application-p2.properties
    6. resource application-p3.properties - HERE IS THE TRICK! this will overwrite properties defined in external files for p1 and p2 with values from resource version of p3
    7. external application-p3.properties

    So keep in mind that last wins but also that resource goes just before external

提交回复
热议问题