spring cloud - /bus/refresh 405

在升级Spring Cloud后遇到配置刷新失败的问题,通过添加properties并调整POST请求的content-type为application/json解决了初步问题。然而,这导致偶尔的405错误。最终,在config-server中添加monitor依赖并测试,成功实现稳定刷新。
摘要由CSDN通过智能技术生成

之前项目升级sprint-cloud,导致原本工作正常的刷新配置不work了。
下面是我的解决的办法:
/bus/refresh

management.endpoints.web.exposure.include=refresh,health,info,bus-refresh
management.endpoints.bus-refresh.enabled=true

加完这两个properties之后,可以通过postman测试,http://host:port/actuator/bus-refresh 是可以刷新config-server

还有一种,则是在通过代码发起http请求刷新config-server中心
一开始,我直接使用rest template

restTemplate.exchange(BUS_CONFIG_URL, HttpMethod.POST, null, Void.class);

尝试运行代码,后台还是会报405 , method not allow

然后经过我的研究发现,你必须要为请求设置content-type application/json
所以,我把我的代码改成了

MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        HttpEntity httpEntity = new HttpEntity(parts);
        restTemplate.exchange(BUS_CONF
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值