chanred
chanred
2019-01-19 11:47

为什么springcloud配置中心服务端获取到最新配置,但客户端端没有拉取最新信息?

20
  • spring
  • java

最近在练习springcloud项目,在练习config配置中心时,已经实现了在GitHub上更新配置,配置中心服务端拿到了配置,但客户端并没有去拉取配置。

环境

jdk:1.8

springboot:2.0.6.RELEASE

SpringCloud:Finchley.SR2

服务端pom如下

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</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-netflix-eureka-client</artifactId>
        <version>2.0.2.RELEASE</version>
    </dependency>

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

    </dependencies>

配置如下

server:
  port: 8888
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
  instance:
      prefer-ip-address: true

spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: https://github.com/*****/seekbean.git
          username: *********
          password: *********
          basedir: /E:/MyDownloads/springboot
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest

management:
  endpoints:
    web:
      exposure:
        include: "*"

客户端pom如下

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

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

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

客户端配置如下

spring:
  application:
    name: orderapi
  cloud:
    config:
      discovery:
        enabled: true
        service-id: CONFIG
      profile: dev
  rabbitmq:
      host: localhost
      port: 5672
      username: guest
      password: guest
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    bus-refresh:
      enabled: true

当我在GitHub上编辑更新我的配置时,会向我的config的服务端发送请求,webhooks配置为

图片说明

每次更新之后配置,我的config服务都能拿到最新配置

图片说明

但客户端却没有主动去拉取配置,无法得到实时的配置信息

图片说明

客户端代码如下

@Data
@Component
@ConfigurationProperties("girl")
@RefreshScope
public class TestConfig {

    private String name;
    private String age;
}
@RestController
@RequestMapping("/girl")
public class EnvController {

    @Autowired
    private TestConfig testConfig;

    @GetMapping("print")
    public String print(){
        return "name:"+testConfig.getName()+",age:"+testConfig.getAge();
    }

}

当我在push我的配置时,config服务端拿到了配置,其控制台也输出了相应信息,但客户端的控制台却毫无反应,求大神帮忙看看,不胜感激

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答