spring cloud Feign 使用 @RequestLine 注解遇到的问题
package com.itmuch.cloud; import org.springframework.cloud.netflix.feign.FeignClient; import com.itmuch.cloud.entity.User;
import com.itmuch.config.FeignConfiguration; import feign.Param;
import feign.RequestLine;
/**
* 客户端请去
* @author Administrator
*
*/
@FeignClient(name="microservice-provider-user",configuration=FeignConfiguration.class)
public interface UserFeignClient { @RequestLine("GET /simple/{id}")
public User findById(@Param("id") Long id); }
启动报错: Method getLinksForTrack not annotated with HTTP method type (ex. GET, POST)
网上百度下都是说 @RequestLine is a core Feign annotation, but you are using the Spring Cloud @FeignClientwhich uses Spring MVC annotations.
意思就是feign 默认使用的是spring mvc 注解(就是RequestMapping 之类的), 所以需要配置feign的Configuration ..
很显然我上面的代码显示我配置了 configuration ..
package com.itmuch.config; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import feign.Contract; @Configuration
public class FeignConfiguration { @Bean
public Contract feignConfiguration(){
return new feign.Contract.Default();
}
}
.. 但是还是会报错。。 最后发现 是 feignConfiguration 这个命名的问题,和 类名一样。。 我随便该了一个名字就可以正常启动了。。
可能是@Bean 的原因。。接下来我查了下:
@Bean是一个方法级别上的注解,主要用在@Configuration注解的类里,也可以用在@Component注解的类里。添加的bean的id为方法名。
注意 添加bean的 ID 是 方法名。
那么配置一个和 @Configuration 注解的类同名的 ID 名的 bean 有什么影响吗
<bean id="feignConfiguration" class="org.springframework.context.annotation.Configuration">
我觉得是spring 把 @Configuration 注解的类不注册到 spring 容器中,由于正好你定义的bean 的id 和 类名相同,导致spring没有注册该bean,
所以相当于没有配置启用feign 注解,所有报错。。
上面是我的猜测,知道的大神可以指教一下。
spring cloud Feign 使用 @RequestLine 注解遇到的问题的更多相关文章
- 笔记:Spring Cloud Feign Ribbon 配置
由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参 ...
- 笔记:Spring Cloud Feign Hystrix 配置
在 Spring Cloud Feign 中,除了引入了用户客户端负载均衡的 Spring Cloud Ribbon 之外,还引入了服务保护与容错的工具 Hystrix,默认情况下,Spring Cl ...
- 笔记:Spring Cloud Feign 其他配置
请求压缩 Spring Cloud Feign 支持对请求与响应进行GZIP压缩,以减少通信过程中的性能损耗,我们只需要通过下面二个参数设置,就能开启请求与响应的压缩功能,yml配置格式如下: fei ...
- 笔记:Spring Cloud Feign 声明式服务调用
在实际开发中,对于服务依赖的调用可能不止一处,往往一个接口会被多处调用,所以我们通常会针对各个微服务自行封装一些客户端类来包装这些依赖服务的调用,Spring Cloud Feign 在此基础上做了进 ...
- 第六章:声明式服务调用:Spring Cloud Feign
Spring Cloud Feign 是基于 Netflix Feign 实现的,整合了 Spring Cloud Ribbon 和 Spring Cloud Hystrix,除了提供这两者的强大功能 ...
- Spring Cloud Feign Ribbon 配置
由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参 ...
- Spring Cloud feign
Spring Cloud feign使用 前言 环境准备 应用模块 应用程序 应用启动 feign特性 综上 1. 前言 我们在前一篇文章中讲了一些我使用过的一些http的框架 服务间通信之Http框 ...
- RestTemplate OR Spring Cloud Feign 上传文件
SpringBoot,通过RestTemplate 或者 Spring Cloud Feign,上传文件(支持多文件上传),服务端接口是MultipartFile接收. 将文件的字节流,放入ByteA ...
- 第六章 声明式服务调用: Spring Cloud Feign
我们在使用 Spring Cloud Ribbon 时, 通常都会利用它对 RestTemplate 的请求拦截来实现对依赖服务的接口调用, 而 RestTemplate 已经实现了对 HTTP 请求 ...
随机推荐
- metasploit framework(六):信息收集
nmap 扫描 扫描完毕之后,hosts查看扫描的结果 auxiliary 扫描 使用arpsweep模块扫描 查看设置 设置网卡和目标IP 设置伪造的源IP和源MAC set SHOST <伪 ...
- 修改weblogic启动模式:client改为server
1.生产模式 -> 开发模式 Step 1:将domain下的 /weblogic/domain/app_domain/bin/setDomainEnv.sh文件的PRODUCTION_MODE ...
- web.config中连接字符串的读写和加密解密
转载:https://www.cnblogs.com/shuai/articles/2248703.html 1.先来看看如何在web.config中写入数据库连接字符串.打开web.config文件 ...
- leetcode 数组类型题
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <Windows.h& ...
- Ant 使用指南 与 知识汇总
一.Ant是什么? Ant是一种基于Java和XML的build工具.它可以帮助我们将项目开发过程中需要完成的各种步骤组织起来,通过一个简易的方式来构建整个项目.Ant究竟能做什么呢?这 ...
- 18. 4Sum (通用算法 nSum)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...
- Disruptor并发框架简介
Martin Fowler在自己网站上写一篇LMAX架构的文章,在文章中他介绍了LMAX是一种新型零售金额交易平台,它能够以很低的延迟产生大量交易.这个系统是建立在JVM平台上,其核心是一个业务逻辑处 ...
- ConcurrentMap与CopyOnWrite容器
ConcurrentMap接口下有两个重要的实现: ConcurrentHashMap ConcurrentSkipListMap(支持并发排序功能,弥补ConcurrentHashMap) Conc ...
- PHP如何处理yyyyMMddHHmmssSSSZ?
PHP如何处理yyyyMMddHHmmssSSSZ? 更新: 2016-01-05 12:45 作者: wecandoitforev PHP编程中,时间,日期的应用是必不可少的.有一种日期格式:yyy ...
- 安装routeos
直接开机,会看到: 选择全部安装即可,按a.i即可. 默认账号admin,默认没有密码 基本使用 可通过/ip,/interface等可以进去不同子功能模块,可进行print,add,remove等操 ...