我可以使用properties/yml文件配置@FeignClient网址吗? [英] Can I configure a @FeignClient url using a properties/yml file?

查看:1681
本文介绍了我可以使用properties/yml文件配置@FeignClient网址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是创建一个不同步骤的策略,以从2个组件之间的点对点通信转变为使用eureka,ribbon和hystrix的完全爆发式netflix"风格的通信.在每次迭代中,我想添加更多内容,同时尝试限制对实际代码的更改量. Feign是实现此目标的首选客户端框架.第一步是创建一个FeignClient来与服务器通信:

My goal is to create a strategy of different steps to get from a point-to-point communication between 2 components to a "full blown netflix" style of communication using eureka, ribbon, hystrix. With each iteration I want to add more while I try to limit the amount of changes to the actual code. Feign is my preferred client side framework to make this happen. First step is to create a FeignClient to communicate to the server:

@FeignClient(url = "http://localhost:9000")
interface Client {
    @RequestMapping(method = RequestMethod.GET, value = "/author/{author}/addedValue/{addedValue}")
    Result addToTotal(@RequestParam(value="author") String author, @RequestParam(value="addedValue") long addedValue);
}

这可行,但是我不希望URL在注解中进行硬编码.我想要这个:@FeignClient() 并具有以下属性构造:client.url: http://localhost:9000

This works but I don't want the URL to be hardcoded in the annotation. I would like to have this: @FeignClient() and have a properties construct like: client.url: http://localhost:9000

到目前为止,我找不到有关如何进行配置的任何线索,也无法在spring-cloud资源中找到解决方案.

So far I couldn't find any clues on how to configure that and I couldn't find a solution in the spring-cloud sources.

可以,如果可以的话;怎么样?

Can it be done and if yes; how?

推荐答案

可以使用"serviceId"代替"url"来完成.例如

It can be done with a "serviceId" instead of a "url". E.g.

@FeignClient("foo")
interface Client { ... }

foo.ribbon.listOfServers: localhost:9000

例如参见 http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-ribbon-without-eureka 用于文档.

这篇关于我可以使用properties/yml文件配置@FeignClient网址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆