Spring Boot:将系统属性传递给Maven
我尝试过:
mvn -Dspring.profiles.active=dev spring-boot:run
,但不影响我的默认配置.我在Google上搜索了一下,发现:
but it does not affect my default configuration. I've googled a little and found:
mvn -DargLine="-Dspring.profiles.active=dev" spring-boot:run
但如果也失败.
当我跑步时:
mvn package
然后:
java -Dspring.profiles.active=test -jar target/app-1.0.0.jar
它按预期方式工作(配置文件已更改),但无法从资源目录(FileNotFound异常)中找到文件,该文件的加载方式如下:
it works as expected (the profile is changed) but fails to find file from resource dir (FileNotFound exception) which is loaded this way:
new File(getClass().getClassLoader().getResource("data.yml").getFile())
使用maven运行应用程序时,此文件没有问题.
There is no problem with this file when maven is used to run the app.
有什么建议吗?
尝试通过以下方式运行应用程序:
Try running your application with:
mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=dev"
我不知道您使用的是哪个版本,请检查此问题a>也是
I don't know which version your are using but check this issue too