我正在使用 Gradlespring-boot
插件,我需要选择一个 spring 活动配置文件来进行测试运行。
我该如何通过spring.profiles.active
系统属性到bootRun
插件的任务?
已经失败的事情:
task bootRunLocal {
systemProperty "spring.profiles.active", "local"
System.setProperty("spring.profiles.active", "local")
tasks.bootRun.execute() // I suspect that this task is executed in a separate JVM
}
一些命令行魔法也失败了:
./gradle -Dspring.profiles.active=local bootRun
有人可以帮我解决我的麻烦吗?
从答案和评论更新:
我可以通过执行以下操作来设置 systemProperty 并将其传递给 spring 容器:
run {
systemProperty "spring.profiles.active", "local"
}
但是,当我这样做时,将为两者设置本地配置文件bootRun
任务和bootRunLocal
任务。我需要一种方法来设置此属性bootRunLocal
任务和呼叫booRun
任务来自bootRunLocal
.
这听起来可能很简单,但我从 Maven 的结构化世界中得到了平静。
我知道我来晚了...但我最近遇到了这个问题。我试图在命令行上将 spring.profiles.active 和 spring.config.location 设置为系统属性来启动 bootRun 。
因此,要让你的命令行“神奇”发挥作用,只需将其添加到你的 build.gradle 中
bootRun {
systemProperties System.properties
}
然后从命令行运行...
gradle -Dspring.profiles.active=local bootRun
将 local 设置为活动配置文件,无需简单地定义单独的任务来添加 env 变量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)