How to set Spring profile from system variable?

前端 未结 7 1532
无人共我
无人共我 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=<env>

    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 <env>

    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}"
    }
    
    0 讨论(0)
提交回复
热议问题