【问题标题】:Spring-boot: Activate multiple profiles using mvnSpring-boot:使用 mvn 激活多个配置文件
【发布时间】:2019-12-30 08:39:17
【问题描述】:

我正在使用这个命令行来启动我的 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

有什么想法吗?

【问题讨论】:

    标签: spring spring-boot spring-profiles


    【解决方案1】:

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

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

    【讨论】:

    • 这是由于 mvn spring-boot 插件...它接受-Dspring-boot.run.profiles="bo,pre" 以启动具有许多配置文件的应用程序。为什么它只需要一个配置文件,可能是一个错误,我不确定。如果您尝试:java -Dspring.profiles.active="bo,pre" -jar YourFatJar.jar,那么您将激活所有配置文件。希望对你有帮助
    【解决方案2】:

    根据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
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-05
        • 2017-02-05
        • 2017-04-12
        • 1970-01-01
        • 2011-07-17
        • 2020-09-20
        • 2014-10-29
        • 2011-06-05
        相关资源
        最近更新 更多