springcloud配置统一配置中心

1配置config-server

实现创建一个eureka client  见https://blog.csdn.net/qq_38522268/article/details/98465868

添加依赖

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>

启动类加注解@EnableConfigServer

@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigApplication {

   public static void main(String[] args) {
      SpringApplication.run(ConfigApplication.class, args);
   }

}

application.yml配置

spring:
  application:
    name: config
  cloud:
      config:
        server:
          git:
            uri: 
            username: 
            password: 
eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:8761/eureka/

2配置config-client

引入依赖

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-config-client</artifactId>
</dependency>

修改application.yml为bootstrap.yml

相关配置:

spring:
  application:
    name: product
  cloud:
      config:
        discovery:
          enabled: true
          service-id: CONFIG

3配置springcloud bus

先启动rabbitmq

config_server端:添加依赖

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

配置

#暴露出接口bus-refresh
management:
  endpoints:
    web:
      exposure:
         include: "*"

config_client端:添加依赖

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency>

注意

使用配置的地方使用@RefreshScope

4.git上配置/actuator/bus-refresh自动刷新springcloud配置统一配置中心