问题
在学习Spring cloud config模块时,一般都是跟着官网的Centralized Configuration | quick-start做一遍.
但在下面这步的时候,出现问题了:
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
复制代码
最后一句出现了红线,也就是这个无效了。
如果你无视这个问题,继续往下做:
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。
原因
在docs.spring.io | 50.2 Exposing Endpoints这个文档讲到了:
management.security.enabled=false被删除的原因
这里就不贴表的截图了,可以点击上面的连接详细查看,会发现除了health和info两个支持web访问外,其他的默认不支持web访问。
解决方法
在bootstrap.properties文件中添加下面的代码 management.endpoints.web.exposure.include=*
暴露全部endpoints,你也可以指定需要暴露的endpoints。
本文介绍了在使用Spring Cloud Config时遇到的配置刷新问题及解决办法。当使用post方法请求刷新端点时出现404错误,是因为默认情况下并非所有管理端点都公开。文章提供了解决方案,即修改bootstrap.properties文件以暴露所有或特定管理端点。
553

被折叠的 条评论
为什么被折叠?



