我已经在src/main/resources下创建了2个文件:
- application.properties
- application-local.properties
第一个具有从环境变量中获取值的属性,而后者具有固定值。
根据这里的具体情况,我以如下方式启动了spring boot:
mvn spring-boot:run -Dspring.profiles.active=local
但是,不产生任何影响,并且应用程序局部。属性似乎被忽略了。
提示吗?
是的,如果你使用spring-boot插件运行,你必须通过-Dspring-boot.run.profiles
传递配置文件,尝试
mvn spring-boot:run -Dspring-boot.run.profiles=local
试试这个,它为我工作!
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=something"
检查这篇文章是否有启发!
Maven spring boot run debug with arguments
在同一路径作为现有的application.properties文件,您可以创建2个环境文件:
application-local.properties
application-server.properties
调用local,可以运行以下命令:
$ java –jar -Dspring.profiles.active=local app.jar
或者,您可以直接在应用程序中调用它。属性文件:
spring.profiles.active=local