FeignClient 动态获取nacos中的配置,线上更改后能热更新

发布时间 2023-07-25 20:11:11作者: 悄悄的来,匆匆的走

1.设置nacos变量在一个类中

@Component
@RefreshScope
@ConfigurationProperties(prefix = "testC")
public class SupplierInfoRakuten {

    private String version;

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }
}
@RefreshScope 刷新nacos配置

2.在FeignClient中设置URI

@FeignClient(value = "TestApi", url = "${testC.version}")
@RefreshScope
public interface TestApi {

    @RequestMapping(value ="/cc",method = RequestMethod.GET,produces = "application/xml;charset=utf-8")
    @ResponseBody
    PropertyResponse myPropertyList(URI uri, @SpringQueryMap PropertyRequest propertyRequest,@RequestHeader("aa") String xApiKey);

}

 

3.设置配置文件test.yml

testC:
 version: 1.0

经过这三步就可以了