Spring Cloud之ConfigServer

本文介绍下Spring Cloud配置中心,以及具体实现(GIT作为配置文件管理)


POM:

 

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-monitor</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bus-amqp</artifactId>
    </dependency>
</dependencies>


bootstrap.yml:

spring:
  application:
    name: ConfigServer

application.yml:

---
server:
  port: 8888
management:
  context-path: /admin
spring:
  profiles: Single
  cloud:
    config:
      server:
        git:
          uri: https://github.com/zxmthinker/config.git
          username: 
          password: 
          


  rabbitmq:
     host: 192.168.199.197
    port: 5672
    username: admin
    password: admin
eureka:
  environment: dev  #test,prod
  instance:
    statusPageUrlPath: ${management.contextPath}/info
    healthCheckUrlPath: ${management.contextPath}/health
    hostname: 10.25.193.111
    instanceId: ${spring.application.name}:${server.port}:${random.value}
    leaseRenewalIntervalInSeconds: 10
    leaseExpirationDurationInSeconds: 30
  client:
   registerWithEureka: true
   fetchRegistry: true
   serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:8761/eureka/
   region: default
   preferSameZoneEureka: true
   useDnsForFetchingServiceUrls: false
   healthCheck: true
logging:
  config: classpath:logback.xml
 
GIT:
以上图为例
Gateway.properties:Gateway公共配置文件
Gateway.yml:Gateway公共配置文件
Gateway-G8771:profile为G8771的配置文件
 
如何访问
http://localhost:8888/Eureka/Single/dev
Eureka:微服务名称
Single:profile名称
dev:GIT上的分支
 
客户端如何配置
bootstarp.yml
spring:
  application:
    name: Eureka
  cloud:
    config:
      uri: http://10.25.193.111:8888
application.yml
spring:
  profiles: G8771
  cloud:
    config:
      profile: G8771
      label: dev
 
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值