How to set Spring profile from system variable?

前端 未结 7 1563
无人共我
无人共我 2020-12-07 18:12

I have a Spring project which uses another project. Each project has its own spring profile initialize from java code using applicationContext.xml and *.p

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 19:06

    You can set the spring profile by supplying -Dspring.profiles.active=

    For java files in source(src) directory, you can use by System.getProperty("spring.profiles.active")

    For java files in test directory you can supply

    • SPRING_PROFILES_ACTIVE to

    OR

    Since, "environment", "jvmArgs" and "systemProperties" are ignored for the "test" task. In root build.gradle add a task to set jvm property and environment variable.

    test {
        def profile = System.properties["spring.profiles.active"]
        systemProperty "spring.profiles.active",profile
        environment "SPRING.PROFILES_ACTIVE", profile
        println "Running ${project} tests with profile: ${profile}"
    }
    

提交回复
热议问题