Spring Boot:将系统属性传递给Maven [英] Spring Boot: passing system properties to maven

查看:97
本文介绍了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"

我不知道您使用的是哪个版本,请检查此问题也是

I don't know which version your are using but check this issue too

这篇关于Spring Boot:将系统属性传递给Maven的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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