在使用springcloud的时候,如果基于springboot2的版本的配置中心,无法使用SVN的刷新功能(修改配置后不需要重启服务器),那么需要重新按照新版本的要求进行配置
#yml格式
management:
endpoints:
web:
exposure:
include: refresh
#properties文件格式
management.endpoints.web.exposure.include=*
同时在控制层需要加上相应注解
@RestController
@RefreshScope // 使用该注解的类,会在接到SpringCloud配置中心配置刷新的时候,自动将新的配置更新到该类对应的字段中。
如果用httpclient的post请求,地址栏就无法请求,那么会报405,使用main方法测试一下,再测试是否在SVN配置文件更新后自动刷新,以下代码可以参考一下
package com.demo.spring.book.service.api;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
/**
* RefreshClinet
*
* @author 10905 2019/2/7
* @version 1.0
*/
public class RefreshClinet {
public static void main(String[] args) throws IOException {
// 创建默认的客户端
CloseableHttpClient httpClient = HttpClients.createDefault();
// 调用post服务
HttpPost httpPost=new HttpPost("http://localhost:8080/actuator/refresh");
// 获取响应
CloseableHttpResponse response = httpClient.execute(httpPost);
// 解析响应
System.out.println("\n\n"+EntityUtils.toString(response.getEntity()));
}
}