zoukankan      html  css  js  c++  java
  • 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);
    }
     
  • 相关阅读:
    C#控件刷新
    [转载] 尺度不变特征变换匹配算法
    C++ windows 多线程 互斥锁
    堆栈内存申请,以及32位程序内存上限
    dumpbin检查Dll
    CV_Assert
    Linux复习
    操作系统复习
    P/NP问题
    程序
  • 原文地址:https://www.cnblogs.com/lshan/p/10669068.html
Copyright © 2011-2022 走看看