首页 > 其他分享 >SpringBoot引入Feign

SpringBoot引入Feign

时间:2024-06-03 16:03:59浏览次数:26  
标签:Feign github SpringBoot openfeign feign 11.10 io 引入 org

首先我们先来了解一下Feign主要是做什么的:使用接口方式调用服务,它让微服务之间的调用变得更简单,类似controller调用service

一、引入POM依赖

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>3.1.8</version>
            <exclusions>
                <exclusion>
                    <artifactId>HdrHistogram</artifactId>
                    <groupId>org.hdrhistogram</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>bcprov-jdk15on</artifactId>
                    <groupId>org.bouncycastle</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jsr305</artifactId>
                    <groupId>com.google.code.findbugs</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-okhttp</artifactId>
            <version>11.10</version>
        </dependency>

        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-httpclient</artifactId>
            <version>11.10</version>
        </dependency>

        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-gson</artifactId>
            <version>11.10</version>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-slf4j</artifactId>
            <version>11.10</version>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-core</artifactId>
            <version>11.10</version>
        </dependency>

二、application增加EnableFeignClients

三、声明代用的接口Interface

@FeignClient(url = "https://aaa.gateway.com", name = "testApi")
public interface TestApi {

    @PostMapping(value = "/aa/bb/test")
    JSONObject testApiInfo(@RequestBody TestRequest testRequest);

}

标签:Feign,github,SpringBoot,openfeign,feign,11.10,io,引入,org
From: https://blog.csdn.net/Just_do_it_HZF/article/details/139416764

相关文章