Using @RequestLine with Feign

妖精的绣舞 提交于 2019-12-20 12:26:53

问题


I have a working Feign interface defined as:

@FeignClient("content-link-service")
public interface ContentLinkServiceClient {

    @RequestMapping(method = RequestMethod.GET, value = "/{trackid}/links")
    List<Link> getLinksForTrack(@PathVariable("trackid") Long trackId);

}

If I change this to use @RequestLine

@FeignClient("content-link-service")
public interface ContentLinkServiceClient {

    @RequestLine("GET /{trackid}/links")
    List<Link> getLinksForTrack(@Param("trackid") Long trackId);

}

I get the exception

Caused by: java.lang.IllegalStateException: Method getLinksForTrack not annotated with HTTP method type (ex. GET, POST)

Any ideas why?


回答1:


I wouldn't expect this to work.

@RequestLine is a core Feign annotation, but you are using the Spring Cloud @FeignClient which uses Spring MVC annotations.




回答2:


Spring has created their own Feign Contract to allow you to use Spring's @RequestMapping annotations instead of Feigns. You can disable this behavior by including a bean of type feign.Contract.Default in your application context.

If you're using spring-boot (or anything using Java config), including this in an @Configuration class should re-enable Feign's annotations:

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


来源:https://stackoverflow.com/questions/29985205/using-requestline-with-feign

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!