【发布时间】:2021-11-02 00:46:27
【问题描述】:
有没有办法从 Maven 配置中为命令行设置参数?也许是一些插件?
我需要使用以下 VM 选项在 Spring Boot 上运行我的服务:
-Dspring.config.additional-location=classpath:/config/business-config.yml
我尝试过使用maven-surefire-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
-Dspring.config.additional-location=classpath:/config/business-config.yml
</argLine>
</configuration>
</plugin>
和spring-boot-maven-plugin:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Dspring.config.additional-location=classpath:/config/business-config.yml
</jvmArguments>
</configuration>
</plugin>
但这对我不起作用。我通过从 IDEA Intellij 本地运行我的 maven 项目作为 Spring Boot 应用程序进行测试。如果我在 IDEA 配置中设置了这个选项,那么它可以正常工作。
有什么想法吗?
【问题讨论】:
-
当你构建 jar 并运行它时会发生什么?因为那是你应该只关心的
-
没什么。构建成功,但是我通过IDEA启动服务时没有安装VM选项。没有任何异常或错误。但是,如果我在 IDEA 的编辑配置中设置了 VM 选项,那么它就会正确应用
-
“但是当我通过IDEA启动服务时没有安装VM选项” - 我说的是构建可执行jar。它不像您将在您的 IDE 中运行 prod。你知道spring的可执行jar是什么吧?
标签: java spring spring-boot maven cmd