1. 程式人生 > >SpringCloud消費者報錯:'org.springframework.cloud.openfeign.FeignContext' that could not be found.

SpringCloud消費者報錯:'org.springframework.cloud.openfeign.FeignContext' that could not be found.

springboot版本:2.0.2.RELEASE,springcloud版本:Finchley.RC2

在使用Feign消費服務者時,首先引入feign的jar包

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-feign</artifactId>
</dependency>

然後在入口類中加入註解@EnableFeignClients,但是卻引不進來

後來引入

<dependency>
<groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-openfeign-core</artifactId> <version>2.0.0.RC2</version> </dependency>

註解成功引入,但是啟動報錯:

2018-06-20 19:33:53.799 ERROR 20984 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
***************************
APPLICATION FAILED TO START
***************************
Description:
Field productClient in com.zsl.order.controller.OrderController required a bean of type 'org.springframework.cloud.openfeign.FeignContext' that could not be found.

- Bean method 'feignContext' not loaded because @ConditionalOnClass did not find required class 'feign.Feign'
Action:

Consider revisiting the conditions above or defining a bean of type 'org.springframework.cloud.openfeign.FeignContext' in your configuration.

報錯原因:jar包引入錯誤

解決方法:

將openfeign的jar包換為

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-openfeign</artifactId>
   <version>2.0.0.RC1</version>
</dependency>
問題解決