Spring-boot: 使用 mvn 激活多个配置文件

Spring-boot: Activate multiple profiles using mvn

我正在使用此命令行来启动我的 spring-boot 服务:

mvn clean compile -DskipTests \
    spring-boot:run \
    -Dspring-boot.run.arguments=--spring.profiles.active="bo,pre"

我正在使用两个配置文件:--spring.profiles.active="bo,pre"。从上面的命令可以看出,我正在激活 bopre 配置文件。

但是,当我的服务启动时,我只看到 bo 配置文件处于活动状态:

 /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.4.RELEASE)

2019-12-30 09:33:08.013  INFO...  : Starting ApiApplication on psgd with PID 30578 (/home/jeusdi/projects/repositori-digital/rep-digital-api/target/classes started by jeusdi in /home/jeusdi/projects/repositori-digital/rep-digital-api)
2019-12-30 09:33:08.022 DEBUG ...  : Running with Spring Boot v2.0.4.RELEASE, Spring v5.0.8.RELEASE
2019-12-30 09:33:08.027  INFO ...  : The following profiles are active: bo

有什么想法吗?

根据 documentation 您必须添加 spring.profiles.include 如下。

spring.profiles.include:
  - pre

当您在 application.properties 文件

中使用以下属性时,应该激活这两个配置文件
spring.profiles.active=pre
spring.profiles.include=bo

或者如果您真的想将活动配置文件指定为命令行参数,您可以对多个配置文件使用以下命令。

mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=bo,--spring.profiles.include=pre 

如果您想添加更多活动配置文件,请使用以下命令。

mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=bo,--spring.profiles.include=pre,--spring.profiles.include=another

改为在命令行中使用此 属性:-Dspring-boot.run.profiles="bo,pre"

mvn clean compile -DskipTests spring-boot:run -Dspring-boot.run.profiles="bo,pre"

mvn clean compile -DskipTests spring-boot:运行 -Dspring-boot.run.profiles=foo,boo