依赖:

<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)的更多相关文章

  1. Feign Client 原理和使用

    Feign Client 原理和使用 一块石头 ​ 公众号:好奇心森林 ​关注他 创作声明:内容包含虚构创作 6 人赞同了该文章 最近一个新项目在做后端HTTP库技术选型的时候对比了Spring We ...

  2. No fallback instance of type class found for feign client user-service(转)

    1.错误日志 在 feign 开启熔断,配置 fallback 类,实现当前接口的实现类时,报错信息如下: Error starting ApplicationContext. To display ...

  3. spring cloud feign覆写默认配置级feign client的日志打印

    一.覆写fegin的默认配置 1.新增配置类FeignConfiguration.java package com.config; import org.springframework.context ...

  4. 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 ...

  5. spring cloud关于feign client的调用对象列表参数、设置header参数、多环境动态参数试配

    spring cloud关于feign client的调用 1.有些场景接口参数需要传对象列表参数 2.有些场景接口设置设置权限等约定header参数 3.有些场景虽然用的是feign调用,但并不会走 ...

  6. spring cloud多个消费端重复定义feign client问题

    spring cloud消费端调用服务提供者,有两种方式rest+ribbon和Feign,Feign是一个声明式的伪Http客户端更为简单易用,所以我们项目选用Feign作为服务通讯方式 项目有6个 ...

  7. client交互技术简单介绍

    随着网络应用的不断丰富,client交互技术也如雨后春笋一般,遍地开花. 正是这些技术的支持,我们的互联网世界变得更加丰富多彩.一个浏览器上.不用说是简单的动画效果,就是一个Office应用也能顺畅的 ...

  8. Feign【替换默认的feign client】

    说明: feign默认情况下使用的是JDK原始的URLConnection发送的HTTP请求,没有使用到连接池,但是对每个地址会保持长连接,即HTTP的persistence connection.我 ...

  9. Is it possible to create @Around Aspect for feign.Client

    https://github.com/spring-cloud/spring-cloud-openfeign/issues/59 看到github 有人问这个问题,做了个示例: import org. ...

随机推荐

  1. Django--bug--ImproperlyConfigured: The SECRET_KEY setting must not be empty.

    Django配置Restframework后,建立用户模型,执行迁移的时候报如下错误: django.core.exceptions.ImproperlyConfigured: The SECRET_ ...

  2. PHP 如何自定义函数

    PHP 如何自定义函数 使用Function来自定义一个函数:格式如下:function function_name( $data ){ /** * 函数操作 */}注意:函数命名和自定义变量一样.只 ...

  3. mac下面 ,启动2个桌面版appium的方法

    分别打开2个终端,分别输入 appium 就可以分别起2个appium桌面版,然后设置端口 即可 参考: https://blog.csdn.net/qq_15283475/article/detai ...

  4. java1.8 新特性(五 如何使用filter,limit ,skip ,distinct map flatmap ,collect 操作 java集合)

    使用filter 根据 条件筛选 出结果:例如 找出 user 中 age >=15 的用户 package lambda.stream; /** * @author 作者:cb * @vers ...

  5. 客户端负载均衡Feign之二:Feign 功能介绍

    一.Ribboon配置 在Spring cloud Feign中客户端负载均衡是通过Spring cloud Ribbon实现的,所以我们可以直接通过配置Ribbon客户端的方式来自定义各个服务客户端 ...

  6. 学习笔记之Machine Learning by Andrew Ng | Stanford University | Coursera

    Machine Learning by Andrew Ng | Stanford University | Coursera https://www.coursera.org/learn/machin ...

  7. 【ZZ】终于有人把云计算、大数据和人工智能讲明白了!

    终于有人把云计算.大数据和人工智能讲明白了! https://mp.weixin.qq.com/s/MqBP0xziJO-lPm23Bjjh9w 很不错的文章把几个概念讲明白了...图片拷不过来... ...

  8. 10 Skills Every SharePoint Developer Needs

    10 Skills Every SharePoint Developer Needs(原文) This blog post guides you through the essential skill ...

  9. RecyclerView实现ViewPager效果;

    看代码就好了,RecyclerView实现Viewpager的效果,添加了界面的改变监听,用法和普通的RecyclerView一样,还可以设置一次滑动多个界面: public class VpRecy ...

  10. python hashillb 模块

    hashlib主要提供字符加密功能,将md5和sha模块整合到了一起,支持md5,sha1, sha224, sha256, sha384, sha512等算法 import hashlib # ## ...