【无标题】

微服务 Maven Profiles 多环境配置

idea版本:2021.3.3(Community Edition)

项目根pom.xml配置

    </project>
		 <-!- 省略项目其他配置 -->
		   <profiles>
		        <profile>
		            <id>dev</id>
		            <activation>
		                <activeByDefault>true</activeByDefault>
		            </activation>
		            <properties>
		                <profile.active>dev</profile.active>
		            </properties>
		        </profile>
		        <profile>
		            <id>test</id>
		            <properties>
		                <profile.active>test</profile.active>
		            </properties>
		        </profile>
		        <profile>
		            <id>prod</id>
		            <properties>
		                <profile.active>prod</profile.active>
		            </properties>
		        </profile>
		    </profiles>
    </project>

配置项目bootstrap.yml文件

server:
  port: 8888

spring:
  application:
    name: learning-maven-profiles-server
  profiles:
    active: @profile.active@
  logback:
    devLevel: debug
  cloud:
    nacos:   #nacos服务中心配置
      config:
        prefix: learning-maven-profiles-server
        server-addr: ${system.active.nacos.@profile.active@.server-addr}
        namespace: ${system.active.nacos.@profile.active@.namespace}
        file-extension: yaml
        group: DEFAULT_GROUP
      discovery:
        server-addr: ${system.active.nacos.@profile.active@.server-addr}
        namespace: ${system.active.nacos.@profile.active@.namespace}
        group: ${system.active.nacos.@profile.active@.group}

system.active.nacos:
  dev:
    server-addr: 127.0.0.1:8848
    namespace: fe338ffd-9d20-44e3-bbcd-02b69d70649a
    group: DEFAULT_GROUP_DEV
  test:
    server-addr: 127.0.0.2:8848
    namespace: 1a1c5e8c-cc23-4d18-9f6d-bb7b47863632
    group: DEFAULT_GROUP_TEST
  prod:
    server-addr: 127.0.0.3:8848
    namespace: c1b67886-dd99-4aec-87ad-05c62e12944e
    group: DEFAULT_GROUP_TEST
ribbon:
  ReadTimeout: 60000  #请求处理的超时时间
  ConnectTimeout: 60000 #请求连接超时时间
  MaxAutoRetries: 0 #对当前实例的重试次数
  MaxAutoRetriesNextServer: 1 #切换实例的重试次数 1

feign:
  hystrix:
    enabled: false
hystrix:
  command:
    userGetKey:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 5000
#        timeout:
#          enabled: false
logging:
  level:
    com.alibaba: info
  config: classpath:logback-spring.xml
mapper:
  mappers: tk.mybatis.mapper.common.Mapper

启动、打包

在项目Maven进行切换启动或package即可进行不同环境的启动与编译打包
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值