Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using @RequestLine with Feign

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?

like image 283
nickcodefresh Avatar asked May 01 '15 10:05

nickcodefresh


People also ask

Does feign client use RestTemplate?

Without Feign, in Spring Boot application, we use RestTemplate to call the User service. To use the Feign, we need to add spring-cloud-starter-openfeign dependency in the pom. xml file.

How do you pass query parameters in feign client?

Query parameters can be configured in Feign clients by using the @RequestParam annotation from the Spring web framework on method arguments which should be passed as query parameters when calling the remote service.

What is a feign RequestLine?

The @RequestLine Feign annotation specifies the HTTP verb, path, and request parameters as arguments in the Feign client. The path and request parameters are specified using the @Param annotation.

Can we use feign client without Eureka?

6.6 Example: How to Use Ribbon Without Eureka Eureka is a convenient way to abstract the discovery of remote servers so that you do not have to hard code their URLs in clients. However, if you prefer not to use Eureka, Ribbon and Feign also work.


2 Answers

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.

like image 164
Alex Wittig Avatar answered Sep 25 '22 07:09

Alex Wittig


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();
}
like image 30
Michael K Avatar answered Sep 23 '22 07:09

Michael K