Spring 启动: passing system properties to maven

标签 spring maven spring-boot

我尝试过:

mvn -Dspring.profiles.active=dev spring-boot:run

但这并不影响我的默认配置。我用谷歌搜索了一下,发现:

mvn -DargLine="-Dspring.profiles.active=dev"spring-boot:run

但如果也失败了。

当我运行时:

mvn 包

然后:

java -Dspring.profiles.active=test -jar target/app-1.0.0.jar

它按预期工作(配置文件已更改),但无法从资源目录中找到文件(FileNotFound 异常),该文件是这样加载的:

new File(getClass().getClassLoader().getResource("data.yml").getFile())

使用maven运行应用程序时,此文件没有问题。

有什么建议吗?

最佳答案

对于当前版本(>= 2.0.0.RELEASE),参数为-Dspring-boot.run.jvmArguments

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev"

来源:Running your Application with Maven

要激活特定的配置文件,有一个可用的快捷方式:

mvn spring-boot:run -Dspring-boot.run.profiles=dev

来源:Specify Active Profiles

关于 Spring 启动: passing system properties to maven,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28049044/

相关文章:

java - apache-13 错误出现在 maven 的包生命周期中

spring - 无法启动 spring boot 应用程序

maven - 如何在另一个项目中向Spring Boot Jar添加依赖项?

java - Hibernate SessionFactory 与 EntityManagerFactory

java - Spring ,XMLCOConfiguration : Without indicating annotation in xml file how it is working?

Maven GlassFish 插件 : asadmin CreateProcess error=193

java - eclipse + Maven + Tomcat : testing web apps when the WAR is built with custom options

Spring boot Security,Oauth2 将访问 token 替换为来自 facebook 的长期 token

java - Hibernate Criteria 查询 Collections 包含某些元素

java - 我如何在 Spring 中编写此 Mongo 聚合查询?