• maven根据profile变量引入或者不引入依赖,引入不同版本的依赖


    目录

    需求

    例子:

    解决方案

    1. A客户需要RabbitMQ,B客户需要Kafka

    pom.xml配置

    A客户

    B客户

    2.A环境的依赖版本是2.13.3,B环境是2.12.7

     pom.xml配置

     A客户

    B客户


    需求

            根据不同场景、环境,需要引入或者不引入相关的依赖,或者因为外部组件等原因,依赖的版本不一样。

    例子:

    1. A客户需要RabbitMQ,B客户需要Kafka
    2. A环境的依赖版本是2.13.3,B环境是2.12.7

    解决方案

    利用maven的profile,来设置不同环境各自的信息,比如可以配置属性值、依赖等等

    1. A客户需要RabbitMQ,B客户需要Kafka

    pom.xml配置

    1. <profiles>
    2. <profile>
    3. <id>dev</id>
    4. <activation>
    5. <activeByDefault>true</activeByDefault>
    6. </activation>
    7. </profile>
    8. <profile>
    9. <id>rabbitmq</id>
    10. <activation>
    11. <activeByDefault>false</activeByDefault>
    12. </activation>
    13. <dependencies>
    14. <dependency>
    15. <groupId>org.springframework.boot</groupId>
    16. <artifactId>spring-boot-starter-amqp</artifactId>
    17. </dependency>
    18. </dependencies>
    19. </profile>
    20. <profile>
    21. <id>kafka</id>
    22. <activation>
    23. <activeByDefault>false</activeByDefault>
    24. </activation>
    25. <dependencies>
    26. <dependency>
    27. <groupId>org.springframework.kafka</groupId>
    28. <artifactId>spring-kafka</artifactId>
    29. </dependency>
    30. </dependencies>
    31. </profile>
    32. </profiles>

    A客户

    A客户的profile里引入rabbitmq,比如:

       applications.properties

    spring.profiles.active=dev,rabbitmq

    此时可以在application-rabbitmq.properties里配置上rabbitmq相关的属性

    B客户

    B客户的profile里引入kafka,比如:

        applications.properties

    spring.profiles.active=dev,kafka

    2.A环境的依赖版本是2.13.3,B环境是2.12.7

    不同环境,因为其它依赖或者外部组件等原因,需要使用不同版本的依赖

     pom.xml配置

     A客户

    A客户的profile里引入env1,比如:

       applications.properties

    spring.profiles.active=dev,env1

    此时可以在application-rabbitmq.properties里配置上rabbitmq相关的属性

    B客户

    B客户的profile里引入env2,比如:

        applications.properties

    spring.profiles.active=dev,env2

  • 相关阅读:
    不会就坚持43天吧 反向遍历
    Leetcode—125.验证回文串【简单】
    Vue的生命周期
    百度搜索智能化算力调控分配方法
    html 生成1-100的随机数
    华为云HECS云服务器docker环境下安装nacos
    React高级用法
    Python基础入门系列详解20篇
    springcloud: stream整合rocketmq
    Java面试--死锁
  • 原文地址:https://blog.csdn.net/lzhfdxhxm/article/details/125626123