feign client 的简单使用(1)
依赖:
<properties>
<java.version>1.8</java.version>
<feign-core.version>10.2.0</feign-core.version>
<feign-form.version>2.1.0</feign-form.version>
</properties>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
<version>${feign-core.version}</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
<version>${feign-core.version}</version>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>${feign-form.version}</version>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>${feign-form.version}</version>
</dependency>
或者直接使用依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
配置:
@Configuration
@ComponentScan(basePackages = "com.icil.elsa.subscribe.milestone.command.web.job")
public class XxlJobConfig { /* @Autowired
private ObjectFactory<HttpMessageConverters> messageConverters*/; private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class); @Value("${xxl.job.admin.addresses}")
private String adminAddresses;// http:127.0.0.1:8888
//define feign client
@Bean
public XxService xxService() {
return Feign.builder()
// .encoder(new FormEncoder(new JacksonEncoder())) //如果有表单提交,加上表单编解码
// .decoder(new JacksonDecoder()) //
.target(XxlJobService.class, adminAddresses);
}
}
XxService:
import com.alibaba.fastjson.JSONObject;
import feign.Headers;
import feign.Param;
import feign.RequestLine; import java.util.Map; public interface XxlJobService { @RequestLine("GET /ufl-job-admin/jobinfo/pageList?jobGroup={jobGroup}")
JSONObject pageList(@Param(value = "jobGroup") int jobGroup); @RequestLine("POST /ufl-job-admin/jobinfo/add")
@Headers("Content-Type: application/x-www-form-urlencoded")
JSONObject add(Map<String, ?> form); @RequestLine("GET /ufl-job-admin/jobinfo/start?id={id}")
JSONObject start(@Param(value = "id") int id); @RequestLine("GET /ufl-job-admin/jobinfo/stop?id={id}")
JSONObject stop(@Param(value = "id") int id);
}
feign client 的简单使用(1)的更多相关文章
- Feign Client 原理和使用
Feign Client 原理和使用 一块石头 公众号:好奇心森林 关注他 创作声明:内容包含虚构创作 6 人赞同了该文章 最近一个新项目在做后端HTTP库技术选型的时候对比了Spring We ...
- No fallback instance of type class found for feign client user-service(转)
1.错误日志 在 feign 开启熔断,配置 fallback 类,实现当前接口的实现类时,报错信息如下: Error starting ApplicationContext. To display ...
- spring cloud feign覆写默认配置级feign client的日志打印
一.覆写fegin的默认配置 1.新增配置类FeignConfiguration.java package com.config; import org.springframework.context ...
- No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-netflix-ribbon?
... 60 common frames omittedCaused by: java.lang.IllegalStateException: No Feign Client for loadBala ...
- spring cloud关于feign client的调用对象列表参数、设置header参数、多环境动态参数试配
spring cloud关于feign client的调用 1.有些场景接口参数需要传对象列表参数 2.有些场景接口设置设置权限等约定header参数 3.有些场景虽然用的是feign调用,但并不会走 ...
- spring cloud多个消费端重复定义feign client问题
spring cloud消费端调用服务提供者,有两种方式rest+ribbon和Feign,Feign是一个声明式的伪Http客户端更为简单易用,所以我们项目选用Feign作为服务通讯方式 项目有6个 ...
- client交互技术简单介绍
随着网络应用的不断丰富,client交互技术也如雨后春笋一般,遍地开花. 正是这些技术的支持,我们的互联网世界变得更加丰富多彩.一个浏览器上.不用说是简单的动画效果,就是一个Office应用也能顺畅的 ...
- Feign【替换默认的feign client】
说明: feign默认情况下使用的是JDK原始的URLConnection发送的HTTP请求,没有使用到连接池,但是对每个地址会保持长连接,即HTTP的persistence connection.我 ...
- Is it possible to create @Around Aspect for feign.Client
https://github.com/spring-cloud/spring-cloud-openfeign/issues/59 看到github 有人问这个问题,做了个示例: import org. ...
随机推荐
- maven使用配置
一.maven常用的命令 maven通过命令对工程进行编译.测试.打包.发布.运行(基本的顺序) mvn compile:编译 mvn clean:清理,将target下的class文件清理 mvn ...
- [蓝桥杯]ALGO-90.算法训练_出现次数最多的整数
问题描述 编写一个程序,读入一组整数,这组整数是按照从小到大的顺序排列的,它们的个数N也是由用户输入的,最多不会超过20.然后程序将对这个数组进行统计,把出现次数最多的那个数组元素值打印出来.如果有两 ...
- [翻译]Restful Web服务模型
最近我一直在阅读“Rest实践”的草稿:一本几位同事一直在努力编写的书. 他们的目的是解释如何使用Restful Web服务来处理企业面临的许多集成问题. 这本书的核心在于这样一种观点,Web以一个有 ...
- NodeJs使用async让代码按顺序串行执行
描述 由于nodejs中的函数调用都是异步执行的,而笔者在工程开发中函数A需要四五个参数,而这四五个参数值都是通过函数调用获得,因此按顺序写代码时,执行到函数A时,往往函数A需要的参数值因为参数的异步 ...
- ServiceLoader
先从业务场景分析,要完成数据的分析处理功能.根据数据的不同种类,先调用groovy或者python脚本等中的一种处理数据,处理完数据的后需要流程相同. 要支持处理能力的动态扩展,也就是框架完成后,可以 ...
- Jmeter(二十四)Jmeter-Question之“加密请求参数”
日常接口测试碰到参数加密的情况不在少数,当然与之相对的也有解密.直接记录实例: 排除各家用的不一样的加密方式,用的最多的还是MD5加密(16,32).Jmeter3.2版本已经有解决方案 1.${__ ...
- 使用IDEA进行Lua代码调试、自动提示、代码跳转、智能重命名
试了几个Lua IDE后,Lua Studio.Lua Glider.VS+babelua插件.Sublime都不是特别满意.直到发现了国人自创的另一个神奇工具:基于IDEA的EmmyLua插件.该插 ...
- Mysql之 配置文件读取顺序
On Unix, Linux and Mac OS X, MySQL programs read startup options from the following files, in the sp ...
- MySQL8.0.12版本密码修改策略问题
查看密码策略(修改临时密码之后才可查看) show variables like 'validate_password%'; 8之前 validate_password_ 8之后validat ...
- SAS 宏数据运算
74 /*计算两个日期之间间隔多少天:开始时间01DEC2005 结束日期:31JUL2018*/75 %LET N2='31JUL2018'D-'01DEC2005'D+1;76 %PUT & ...