目录
根据不同场景、环境,需要引入或者不引入相关的依赖,或者因为外部组件等原因,依赖的版本不一样。
利用maven的profile,来设置不同环境各自的信息,比如可以配置属性值、依赖等等
- <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客户的profile里引入rabbitmq,比如:
applications.properties
spring.profiles.active=dev,rabbitmq
此时可以在application-rabbitmq.properties里配置上rabbitmq相关的属性
B客户的profile里引入kafka,比如:
applications.properties
spring.profiles.active=dev,kafka
不同环境,因为其它依赖或者外部组件等原因,需要使用不同版本的依赖
A客户的profile里引入env1,比如:
applications.properties
spring.profiles.active=dev,env1
此时可以在application-rabbitmq.properties里配置上rabbitmq相关的属性
B客户的profile里引入env2,比如:
applications.properties
spring.profiles.active=dev,env2