从 IntelliJ 运行时如何激活 Spring Boot 配置文件? [英] How do I activate a Spring Boot profile when running from IntelliJ?
问题描述
我有 5 个环境:
- local (my development machine)
- dev
- qc
- uat
- live
- staging
我希望为每个环境使用不同的应用程序属性,因此我有以下属性文件,每个文件都有不同的数据源 URL:
I want different application properties to be used for each environment, so I have the following properties files each which have a different URL for the datasource:
- application.properties (containing common properties)
- application-local.properties
- application-dev.properties
- application-qc.properties
- application-uat.properties
- application-live.properties
我正在使用 IntelliJ 并在本地机器上的 Gradle 插件中使用 bootRun 运行我的应用程序.我将在所有其他运行 Tomcat 的环境中部署相同的应用程序战争文件.
I am using IntelliJ and running my app using bootRun in the Gradle plugin on my local machine. I will be using deploying the same application war file on all other environments which run Tomcat.
我尝试添加:
--spring.profiles.active=local
--spring.profiles.active=local
到脚本参数下的运行配置.
to the run configuration under script parameters.
我已经尝试添加
-Dspring.profiles.active=local
-Dspring.profiles.active=local
到VM选项下的运行配置.
to the run configuration under VM options.
都不起作用.我在启动时一直看到 INFO 消息说:没有设置活动配置文件,回退到默认配置文件:默认
Neither work. I keep seeing the INFO message on startup say: No active profile set, falling back to default profiles: default
如果我使用
gradle bootRun
但是我先设置了环境变量
but I first set the environment variable
set SPRING_PROFILES_ACTIVE=local
然后一切正常.
所以我的问题是,当从 IntelliJ 运行 bootRun 时,如何激活我的本地 Spring Boot 配置文件?
So my question is, how do I activate my local spring boot profile when running bootRun from IntelliJ ?
推荐答案
我将 -Dspring.profiles.active=test
添加到 VM 选项,然后重新运行该配置.它工作得很好.
I added -Dspring.profiles.active=test
to VM Options and then re-ran that configuration. It worked perfectly.
这个可以设置
- 选择<代码>运行|编辑配置...
- 转到
配置
标签 - 展开
Environment
部分以显示VM 选项
- Choosing
Run | Edit Configurations...
- Go to the
Configuration
tab - Expand the
Environment
section to revealVM options
这篇关于从 IntelliJ 运行时如何激活 Spring Boot 配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!