开发者社区> 问答> 正文

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  

展开
收起
kun坤 2020-05-31 21:37:02 860 0
1 条回答
写回答
取消 提交回答
  • 我已经自己找到原因了,但是不告诉你们,O(∩_∩)O哈哈~。。过年好######支持,其实遇到技术问题问没用的,没人能回答你######这种精神就不对啊,要开源��######把consol的配置 配置到bootstrap.yml就可以了######@J-Fla 我用consul的key-value可以,但是使用yaml 就不行,请指教,consul的key和注解的java类怎么个对应关系。######把consol的配置 配置到bootstrap.yml就可以了 , 已经在第2个留言那里回复过了######@J-Fla ,首先我真的认真的看了你的帖子了,我的主要代码如下: 这种yaml方式说什么也拿不到name的值,但是我用key-value方式是可以的,请指正。######你好,因为我之前实验过,如果consol的链接信息不写在bootstrap.yml中的话,springboot 实际上相当于没有配置使用 consul 的这个config ,明白了吗,所以你看一下 是否链接consul的信息是在boostrap.yml中配置的######https://my.oschina.net/u/1262235/blog/3035425

    2020-05-31 21:37:09
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建基于SpringCloud的微服务应用 立即下载
MongoShake -- Multi Active-Active and Cross-Region Disaster Recoverable MongoDB Service 立即下载
低代码开发师(初级)实战教程 立即下载