使用Spring Cloud Feign远程调用
来源:互联网 发布:软件著作权年限 编辑:程序博客网 时间:2024/05/24 05:39
Spring Cloud Feign简介参考:http://blog.csdn.net/neosmith/article/details/52449921
根据专家学者提供的账号密码,要在用户表注册一个专家学者账号(用户和专家学者不同的数据库)
在userContorller.java写一个方法:注册专家学者账号
/** * 专家学者注册 * * @param username * @param password * @return */@ApiOperation(value = "专家学者注册")@RequestMapping(value = "/registExpert", method = RequestMethod.POST)public long registExpert(@RequestParam("username") String username, @RequestParam("password") String password) {User user = new User();user.setUsername(username);user.setPassword(password);userService.insertSelective(user);long userId = user.getUserId();return userId;}
UserClient.java(这里的接口和要远程调用的controller方法声明一样(此处是UserController.java),可直接复制过来,如下所示)
package com.lgsc.cjbd.expert.remote.client;import org.springframework.cloud.netflix.feign.FeignClient;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import com.lgsc.cjbd.vo.Response;@FeignClient(name = "cjbd-user", fallback = UserClientFallback.class)public interface UserClient {/** * 注册专家学者 */@RequestMapping(value = "/user/user/registExpert", method = RequestMethod.POST)long registExpert(@RequestParam("username") String username, @RequestParam("password") String password);}
以及失败回调用UserClientFallBack.java
package com.lgsc.cjbd.expert.remote.client;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.stereotype.Component;import com.lgsc.cjbd.vo.Response;/** * 失败回调 * * @author yeqj */@Componentpublic class UserClientFallback implements UserClient {private static Logger log = LogManager.getLogger(UserClientFallback.class);@Overridepublic long registExpert(String username, String password, String realName) {log.error("远程调用失败,注册专家学者失败,参数:[username=" + username + ",password=" + password + "]");return 0;}}之后再专家学者Service层传递专家学者用户名和密码过去,在用户表新增专家学者注册记录
userClient.registExpert(username, password);即可完成远程调用
阅读全文
1 0
- 使用Spring Cloud Feign远程调用
- spring cloud使用Feign实现远程接口的调用
- Spring Cloud feign使用
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 【Spring Cloud】Feign接口调用
- Spring Cloud学习系列第二章:使用Feign调用服务
- Spring Cloud中如何优雅的使用Feign调用接口
- Spring Cloud Feign 使用方式
- spring cloud feign 调用服务注意问题
- Spring Cloud 声明式服务调用 Feign
- 声明式服务调用:Spring Cloud Feign
- spring cloud Feign(声明式服务调用)
- Spring Cloud之Feign调用token丢失
- spring cloud 使用feign 遇到问题
- Android基于环信开发的即时通讯APP
- 使用TinyXML创建xml文件
- eclipse 无用代码扫描工具UCDetector
- 写高质量OC代码52建议总结:35.用僵尸对象调试内存管理问题
- Faster-RCNN 训练自己数据集的坑记录
- 使用Spring Cloud Feign远程调用
- 关于i++和++i以及&&的逻辑
- banner
- 设计模式(数据结构)—— 组合模式
- eclipse配置tomcat8.5(注意是8.5)
- 【LeetCode】InsertInterval
- Spark核心编程:RDD持久化详解
- struts2创建action几种方式有什么区别?
- 用Shell脚本定时监控Linux下的进程状态并自动重启