由于只想在SpringBoot中使用一下Feign客户端,来访问第三方请求,但因为各种版本问题,一直报各种乱七八糟的错
pom文件<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.12.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.16.20</version><scope>provided</scope></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>2.0.2.RELEASE</version></dependency></dependencies>【日常坑弟视频 踩坑日常之SpringCloud使用Feign各种报错】注意这里的springboot的版本号和openfeign的版本号非常重要,不要盲目使用最新版本
然后是常规操作
在项目启动类上添加@EnableFeignClients注解如下:
@EnableFeignClients@SpringBootApplicationpublic class ClientApplication {public static void main(String[] args) {SpringApplication.run(ClientApplication.class,args);}}如果忘记添加该注解,会报自己定义的FeignClient注入不进去的错
编写接口Interface写FeignClient格式大致像如下方式
@FeignClient(name = "userService",url = "http://localhost:8081/api/server")public interface UserFeignClient {@RequestMapping(value = "https://tazarkount.com/getUserInfo",method = RequestMethod.GET)@ResponseBodyString getUserInfo();}如果未为FeignClient设置name,也会报错,会报一个没有name的错,一看就能明白
好了,日常踩坑的一天,祝各位顺利
- 春季老年人吃什么养肝?土豆、米饭换着吃
- 三八妇女节节日祝福分享 三八妇女节节日语录
- 老人谨慎!选好你的“第三只脚”
- 校方进行了深刻的反思 青岛一大学生坠亡校方整改校规
- 脸皮厚的人长寿!有这特征的老人最长寿
- 长寿秘诀:记住这10大妙招 100%增寿
- 春季老年人心血管病高发 3条保命要诀
- 眼睛花不花要看四十八 老年人怎样延缓老花眼
- 香槟然能防治老年痴呆症? 一天三杯它人到90不痴呆
- 老人手抖的原因 为什么老人手会抖
