A Problem about Spring Cloud Config Auto-refresh

问题

在学习Spring cloud config模块时,通常都是跟着官网的Centralized Configuration | quick-start作一遍.html

但在下面这步的时候,出现问题了:git

configuration-client/src/main/resources/bootstrap.properties

spring.application.name=a-bootiful-client
# N.B. this is the default:
spring.cloud.config.uri=http://localhost:8888
management.security.enabled=false
复制代码

最后一句出现了红线,也就是这个无效了。web

若是你无视这个问题,继续往下作:spring

大体翻译下: 改变git仓库中的a-bootiful-client.properties文件中的message值(好比改成Hello Spring),记得commit一下,你能够经过访问 http://localhost:8888/a-bootiful-client/default来验证config服务器已经知道了改变,你须要调用 refresh方法来强制客户端去获取新的值.......你能够经过使用 post方法去请求 http://localhost:8888/refresh来调用 refresh方法,而后访问 http://localhost:8080/message来验证是否生效。

然而当你使用post方法去请求http://localhost:8888/refresh时,返回的404。bootstrap

缘由

docs.spring.io | 50.2 Exposing Endpoints这个文档讲到了:bash

因为endpoints中会包含不少敏感信息,你须要当心的暴露它们,下面这张表展现了默认暴露的接口。这也是 management.security.enabled=false被删除的缘由

这里就不贴表的截图了,能够点击上面的链接详细查看,会发现除了health和info两个支持web访问外,其余的默认不支持web访问。服务器

解决方法

在bootstrap.properties文件中添加下面的代码 management.endpoints.web.exposure.include=*app

暴露所有endpoints,你也能够指定须要暴露的endpoints。ide

相关文章
相关标签/搜索