spring cloud Feign使用@RequestLine注解问题

spring boot 项目需要调用其它项目的接口试使用spring cloud feign声明式调用。

/**
 * 客户端请去
 * @author Administrator
 *
 */
@FeignClient(name="microservice-provider-user")
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 ..

/**
 * @Description: feign配置使用RequestLine注解
 */
@Configuration
public class FeignClientConfig {

    @Bean
    public Contract feignContract() {
        return new feign.Contract.Default();
    }
}

最后使用Feign的客户端上增加注解就可以使用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);
    
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值