【spring-cloud】spring-cloud-config-client 按照案例练习无法实现bus配置文件刷新

根据网上教程学习spring-cloud,因使用版本不同,练习bus消息总线的时候,动态刷新配置文件时/bus/refresh总是失败。贴出我的配置记录。

config-server

  • pom 文件


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.2.2.RELEASE
         
    
    com.miniy
    config-server
    0.0.1-SNAPSHOT
    config-server
    Demo project for Spring Boot

    
        1.8
        Hoxton.SR1
    

    
        
            org.springframework.cloud
            spring-cloud-config-server
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
        
            org.springframework.retry
            spring-retry
        
        
            org.springframework.boot
            spring-boot-starter-aop
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


  • application.yml
server:
  port: 8767

spring:
  application:
    name: config-server
  cloud:
    config:
      label: master
      server:
        git:
          uri: https://gitee.com/miniygq/sc_learning
          search-paths: respo
          username: miniy
          password: miniy
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  • 启动类
@EnableEurekaClient
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

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

}

config-client

  • pom.xml


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.2.2.RELEASE
         
    
    com.miniy
    config-client
    0.0.1-SNAPSHOT
    config-client
    Demo project for Spring Boot

    
        1.8
        Hoxton.SR1
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.retry
            spring-retry
        
        
            org.springframework.boot
            spring-boot-starter-aop
        
        
            org.springframework.cloud
            spring-cloud-starter-config
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
        
            org.springframework.cloud
            spring-cloud-starter-bus-amqp
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



  • bootstrap.yml 文件,名字为bootstrap 一定不能错
spring:
  application:
    name: config-client
  cloud:
    config:
      label: master
      profile: dev
      #      uri: http://localhost:8767/
      discovery:
        enabled: true
        service-id: config-server
  rabbitmq:
    host: 10.13.14.191
    port: 5672
    username: guest
    password: 123456

server:
  port: 8768
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
// 重要,与spring-boot1.x 版本不同
management:
  endpoints:
    web:
      exposure:
        include: "*"
  • 启动类
@RefreshScope
@EnableEurekaClient
@RestController
@SpringBootApplication
public class ConfigClientApplication {

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

    @Value("${foo}")
    String foo;

    @RequestMapping(value = "/hi")
    public String hi() {
        return foo;
    }
}

最后修改git文件后使用postman对客户端http://10.13.14.21:8768/actuator/refresh进行动态刷新

你可能感兴趣的:(【spring-cloud】spring-cloud-config-client 按照案例练习无法实现bus配置文件刷新)