How to set the Profile using application.properties in Spring?

后端 未结 3 434
借酒劲吻你
借酒劲吻你 2020-12-18 06:35

I would like to set the Profile using application.properties file with the entry:

mode=master

How to set spring.profiles.active in my conte

3条回答
  •  别那么骄傲
    2020-12-18 06:49

    You also can achieve this indirectly via System.setProperty:

    // spring.profiles file: profile1,profile2
    String anotherProfiles = Files.readString(Path.of("spring.profiles")); // or any other file
    // Even some logic can be applied here to anotherProfiles
    System.setProperty("spring.profiles.include", "dev," + anotherProfiles)
    

    This sample can be rewritten a bit to read your application.properties file and take specified profiles for Spring.

提交回复
热议问题