Java 春季启动 2 中的 FeignClient

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52365074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:25:28  来源:igfitidea点击:

FeignClient in spring boot 2

javaspringspring-bootnetflix-feignspring-cloud-feign

提问by Sviatlana

I am trying to migrate from spring boot 1.5 tio 2.0 and faced problem: I changed version of spring-cloud-netflix-corefrom 1.3.4.RELEASEto 2.0.1.RELEASE:

我正在尝试从 spring boot 1.5 tio 2.0 迁移并遇到问题:我将spring-cloud-netflix-core 的版本1.3.4.RELEASE 更改2.0.1.RELEASE

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-netflix-core</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>

Unfortunately, feign library imports failed:

不幸的是,伪装库导入失败:

import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.feign.FeignAutoConfiguration;
import org.springframework.cloud.netflix.feign.FeignClient;

There is no library .feign in new 2.0.1 version. What should I use instead? (connot leave old cloud version because of conflict with spring boot autoconfiguration)

新的 2.0.1 版本中没有库 .feign。我应该用什么代替?(由于与 spring boot 自动配置冲突,不能离开旧的云版本)

采纳答案by Darren Forsythe

Since the 2.xrelease Spring Cloud moved the netflix feign classes to their own project.

2.x发布以来,Spring Cloud 将 netflix feign 类移到了他们自己的项目中。

https://github.com/spring-cloud/spring-cloud-openfeign

https://github.com/spring-cloud/spring-cloud-openfeign

You need to update your re-import with the correct package

您需要使用正确的包更新重新导入

org.springframework.cloud.openfeign

org.springframework.cloud.openfeign

回答by S.K.

You need to import feign as an independent dependency starting from 2.X release:

您需要从 2.X 版本开始将 feign 作为独立依赖项导入:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
    <version>2.0.1.RELEASE</version>
</dependency>