how to set spring.config.location for a gradle spring boot project in Intellij IDEA community version?

WesternGun :

I want to configure spring.config.location or spring.config.additional-location in a Java Spring Boot project using Gradle in my Intellij IDEA community version. It is run in the IDE clicking the little green arrow button, not from command line like java -jar.

Basically, we want to add another folder hierarchy under src/main/resources/config, to load src/main/resources/config/a/ and src/main/resources/config/b/ folder at the same time.

What we have tried all failed:

  • set VM options -Dspring.config.location=classpath:/config/a/
  • pass it to terminal gradle test run
  • set a Environment variable in Run configuration in the IDE "Edit configuration": spring.config.location=classpath:/config/a/,classpath:/config/b/

Any idea? I am with community version so there is no Spring Boot support available in the Enterprise or Ultimate version.

"Not working" means that gradle test cannot pass.

Marko Previsic :

You can set it through an environment variable:

SPRING_CONFIG_LOCATION=classpath:/config/a/,classpath:/config/b/

Note that "spring.config.location" is the name of the JVM argument but the environment variable is written with uppercase letters and underscores.

EDIT:

I don't know exactly why gradle won't pick up your VM options if you configure it as you described. If you want to run it with gradle bootRun, you can add the following to your build.gradle to pass the VM options to the app when running with bootRun:

bootRun {
  systemProperties = System.properties
}

On the other way, if you want to run it only by clicking the green arrow, maybe you should configure the VM options in the Gradle settings inside IntelliJ.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=156016&siteId=1