Feign(一)简单的feign使用过程记录

一、依赖

Spring Cloud版本信息

1 <properties>
2     <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
3 </properties>

openfeign依赖 

 1 <dependencies>
 2     <dependency>
 3       <groupId>org.springframework.cloud</groupId>
 4       <artifactId>spring-cloud-starter-openfeign</artifactId>
 5     </dependency>
 6 </dependencies>
 7 <dependencyManagement>
 8     <dependencies>
 9       <dependency>
10         <groupId>org.springframework.cloud</groupId>
11         <artifactId>spring-cloud-dependencies</artifactId>
12         <version>${spring-cloud.version}</version>
13         <type>pom</type>
14         <scope>import</scope>
15       </dependency>
16     </dependencies>
17 </dependencyManagement>

 二、Application注解:

@EnableFeignClients

三、FeignService:

可以单独使用value/name,也可以使用value/name和url组合的方法来使用;

1 @FeignClient(name = "org-feign-service", url = "http://localhost:8080/o/org")
1 /**
2      * @return The service id with optional protocol prefix. Synonym for {@link #value()
3      * value}.
4      */
5     @AliasFor("value")
6     String name() default "";
1 /**
2      * @return an absolute URL or resolvable hostname (the protocol is optional).
3      */
4     String url() default "";
1 /**
2      * The name of the service with optional protocol prefix. Synonym for {@link #name()
3      * name}. A name must be specified for all clients, whether or not a url is provided.
4      * Can be specified as property key, eg: ${propertyKey}.
5      * @return the name of the service with optional protocol prefix
6      */
7     @AliasFor("name")
8     String value() default "";
注意:FeignService中方法的传参参数。形式要和被调用Controller中的保持一致
1    /**
2      * @param org_id
3      * @return
4      */
5     @GetMapping("/{org_id}")
6     Org findById(@PathVariable(name = "org_id") int org_id);
1   /**
2      * @param org_id
3      * @return
4      */
5     @GetMapping("/{org_id}")
6     public List<Org> findById(@PathVariable(name = "org_id") int org_id) {
7                 ...处理操作...
8         return  orgList;
9     } 

四、在Controller中使用FeignService:

1    @Autowired
2     private OrgFeignService orgFeignService;

 

转载于:https://www.cnblogs.com/zy-stu/p/zy_feign_sty_01.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值