feign调用soap_Spring Cloud 组件 —— feign

feign 作为一个声明式的 Http Client 开源项目。在微服务领域,相比于传统的 apache httpclient 与在 spring 中较为活跃的 RestTemplate 更面向服务化,更易于使用。底层封装了 Jersey 与 CXF 分别用于 REsT 与 SOAP 的服务(对应有 JAX-RS 与 JAX-WS  API),当然也可以配置换成其它类似的实现,比如 OkHttp 、Ribbon 或者 Apache HC 等。

feign 基本用法及注解的使用看官方文档。下面介绍下 Spring Cloud 中的封装及实现细节(Spring Cloud 文档):

一、 基本用法

现有服务提供方:需要调用它的 createUser 方法

@RestController

@RequestMapping("/users")

public class UserController {

@Autowired

private UserService userService;

@RequestMapping(value = "/current", method = RequestMethod.GET)

public Principal getUser(Principal principal) {

return principal;

}

@PreAuthorize("#oauth2.hasScope('server')")

@RequestMapping(method = RequestMethod.POST)

public void createUser(@Valid @RequestBody User user) {

userService.create(user);

}

}

使用 feign 构建消费服务方,遵循以下步骤:

引入 maven 依赖

org.springframework.cloud

spring-cloud-starter-openfeign

1. 启用:使用  @EnableFeignClients注解启动 feign 模块基础功能(扫描 feign client包,使用默认或指定的相关配置等等)

@SpringBootApplication

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值