微服务配置

bootstrap.yml文件如下:

spring:
  application:
    name: 微服务应用名
  cloud:
    config:
      label: ${config.label:dev}
      profile: ${config.profile:dev}
      discovery:
        enabled: true
        serviceId: config-server
eureka:
    instance:
      #Renew频率。默认是30秒,每30秒会向Eureka Server发起Renew操作。
      lease-renewal-interval-in-seconds: 30
      #服务失效时间。默认是90秒,Eureka Server在90秒内没有接收到来自Service Provider的Renew操作,就会把Service Provider剔除。
      lease-expiration-duration-in-seconds: 90
      prefer-ip-address: true
      instance-id: ${spring.cloud.client.ipAddress}:${server.port}
    client:
        serviceUrl:
            defaultZone: ${defaultZones:http://172.20.69.70:1111/eureka/,http://172.20.69.71:1111/eureka/}
        register-with-eureka: true

1、本地调式

将spring.cloud.config.discovery设置为false,然后将配置文件内容复制到application.yml中即可

2、打包部署环境

就是读取git上对应分支的配置,此时将spring.cloud.config.discovery设置为true

配置中心的配置文件application.yml如下

spring:
  application:
    name: config-server
#  profiles:
#    active: native
#  cloud:
#    config:
#      server:
#        native:
#          search-locations: ${config.url:E:/locationConfigCenter}
  cloud:
    config:
      discovery:
        enabled: true
      server:
        git:
          uri: ${config.url:http://git.timacloud.cn/TIMA-DMP/config-center.git}
          searchPaths: ${config.folder:dmp}
          username: ${config.username:jenkins.notify}
          password: ${config.password:J8GUrST5}
          force-pull: true
server:
  port: 2222
eureka:
  instance:
    #Renew频率。默认是30秒,每30秒会向Eureka Server发起Renew操作。
    lease-renewal-interval-in-seconds: 30
    #服务失效时间。默认是90秒,Eureka Server在90秒内没有接收到来自Service Provider的Renew操作,就会把Service Provider剔除。
    lease-expiration-duration-in-seconds: 90
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ipAddress}:${server.port}
  client:
      serviceUrl:
#          defaultZone: ${defaultZones:http://localhost:1111/eureka/}
          defaultZone: ${defaultZones:http://172.20.69.70:1111/eureka/,http://172.20.69.71:1111/eureka/}
      register-with-eureka: true
posted @ 2019-12-25 19:03  再见傅里叶  阅读(552)  评论(0编辑  收藏  举报