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配置

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>rabbitmq</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-amqp</artifactId>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>kafka</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
					<groupId>org.springframework.kafka</groupId>
					<artifactId>spring-kafka</artifactId>
				</dependency>
            </dependencies>
        </profile>
    </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

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值