whs_321 2018-07-23 07:15 采纳率: 11.1%
浏览 2856
已结题

springcloud获取不到consul刷新后个配置

在本地启动了1个 Consul。consul agent -dev

添加了配置

 spring:
  application:
    name: spring-cloud-consul-ok
  cloud:
    consul:
      host: 127.0.0.1
      port: 8500
      discovery:
          enabled: true
          register: true
          healthCheckInterval: 15s
          health-check-timeout: 1s
          instance-id: ${spring.application.name}-${spring.cloud.consul.host}-${spring.cloud.consul.port}
          serviecName: ${spring.application.name}
      config:
        enabled: true
        format: YAML
        data-key: configuration

属性配置类:

@Configuration
@ConfigurationProperties("sample")
@Data
@RefreshScope
public class SampleProperties {
    private String prop = "default data";
}

引用方式:

@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrix
@RestController
@EnableConfigurationProperties
@EnableFeignClients
@Slf4j
public class ConsulAreYouOkApplication {

    @Autowired
    private RibbonHelloService ribbonHelloService;

    @Autowired
    private SampleProperties sampleProperties;

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String areyouok(@RequestParam String name) {
        return ribbonHelloService.sayHi(name)+" "+sampleProperties.getProp();
    }
    ```

看着没什么错,但是一直 拿不到 Consul上面的配置,从日志里面  也可以看到Spring已经检测到了 属性的变化,但是就是一直获取不到新值。

版本如下

spring-boot-dependencies                    1.5.10.RELEASE

spring-cloud-consul-config                     1.3.2.RELEASE

spring-cloud-starter-consul-discovery        1.3.2.RELEASE
  • 写回答

1条回答 默认 最新

  • java_66666 2018-07-23 07:18
    关注

    把consol的配置 配置到bootstrap.yml就可以了

    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败