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

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

经过这三步就可以了

 

posted on 2023-07-25 19:48  悄悄的来,匆匆的走  阅读(982)  评论(0编辑  收藏  举报

导航