如何在Intellij IDEA社区版本中为Gradle Spring Boot项目设置spring.config.location? [英] how to set spring.config.location for a gradle spring boot project in Intellij IDEA community version?

查看:883
本文介绍了如何在Intellij IDEA社区版本中为Gradle Spring Boot项目设置spring.config.location?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Intellij IDEA社区版本中使用Gradle在Java Spring Boot项目中配置spring.config.locationspring.config.additional-location.它是在IDE中单击绿色的小箭头按钮运行的,而不是从java -jar这样的命令行运行.

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.

基本上,我们想在src/main/resources/config下添加另一个文件夹层次结构,以同时加载src/main/resources/config/a/src/main/resources/config/b/文件夹.

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:

  • 设置VM选项-Dspring.config.location=classpath:/config/a/
  • 将其传递到终端gradle test run
  • 在IDE编辑配置"中的Run configuration中设置环境变量:spring.config.location=classpath:/config/a/,classpath:/config/b/
  • 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/

有什么主意吗?我使用的是社区版本,因此在Enterprise或Ultimate版本中没有可用的Spring Boot支持.

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

不工作"表示gradle test无法通过.

"Not working" means that gradle test cannot pass.

推荐答案

您可以通过环境变量进行设置:

You can set it through an environment variable:

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

请注意,"spring.config.location"是JVM参数的名称,但是环境变量是用大写字母和下划线编写的.

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

我不完全知道,如果按照您的说明进行配置,gradle不会选择您的VM选项.如果要使用gradle bootRun运行它,可以在build.gradle中添加以下内容,以在使用bootRun运行时将VM选项传递给应用程序:

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.

这篇关于如何在Intellij IDEA社区版本中为Gradle Spring Boot项目设置spring.config.location?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆