在Spring Boot多模块MAVE项目中的命令行上指定弹簧配置文件

发布于 2025-02-06 07:30:06 字数 1499 浏览 2 评论 0原文

我有 this Multi-Module Spring Boot(v2.7.0)项目。 它是相当肯定的 - 一个具有一个端点的控制器。

├───app
│   ├── pom.xml
│   └───src
│       └───main
│           └───java
│               └───com
│                   └───rb
│                       └─── App.java
├───controller
│   ├── pom.xml
│   └───src
│       └───main
│           └───java
│               └───com
│                   └───rb
│                       └─── MainController.java
└ pom.xml

我正在使用Maven 3.8.4。

我想使用此 Spring Boot的NICE快捷方式

mvn clean install; 
mvn spring-boot:run '-Dspring-boot.run.profiles=local' --projects app

(我是从PowerShell运行的,因此围绕参数的单引号)

Active-Profiles“ rel =” nofollow noreferrer 工作。该应用启动,运行正常,但使用默认配置文件。

的语法起作用,或者为什么不起作用?

我的问题是 - 如何使这个不错 /maven-plugin/reference/htmlsingle/#运行“ rel =“ nofollow noreferrer”>更长的语法在春季作品中提到的:

mvn clean install;
mvn spring-boot:run '-Dspring-boot.run.jvmArguments="-Dspring.profiles.active=local"' --projects app

我还尝试在命令提示符上运行它,以省略这些单引号 - 带有相同的结果。

我将感谢有关问题的任何见解 - 我不是Java的专家 属性&命令行参数。

I've got this multi-module Spring Boot (v2.7.0) project.
It's fairly bare-bone - one Controller with one endpoint.

├───app
│   ├── pom.xml
│   └───src
│       └───main
│           └───java
│               └───com
│                   └───rb
│                       └─── App.java
├───controller
│   ├── pom.xml
│   └───src
│       └───main
│           └───java
│               └───com
│                   └───rb
│                       └─── MainController.java
└ pom.xml

I'm using Maven 3.8.4.

I would like to specify profile on the command line using this Spring Boot's nice shortcut:

mvn clean install; 
mvn spring-boot:run '-Dspring-boot.run.profiles=local' --projects app

(I'm running it from PowerShell, hence the single quotes around the parameter)

However, it doesn't work. The app starts, runs fine, but with the default profile.

My question is - how to make this nice syntax work, or why does it not work?

This uglier longer syntax mentioned in Spring's works:

mvn clean install;
mvn spring-boot:run '-Dspring-boot.run.jvmArguments="-Dspring.profiles.active=local"' --projects app

I also tried running it on Command Prompt omitting those single-quotes - with the same result.

I would appreciate any insights on what could be the issue - I'm no expert in Java's
properties & command-line arguments.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与之呼应 2025-02-13 07:30:06

使用Spring-Boot Maven插件运行时,您必须像

MVN Spring-boot:run -dspring-boot.run.profiles = local一样传递它。

When you run with the spring-boot maven plugin, you have to pass it like this

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文