2
回答
springcloud获取不到consul刷新后个配置
【腾讯云】学生服务器套餐10元/月 >>>   

在本地启动了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
 

举报
J-Fla
发帖于3个月前 2回/325阅
顶部