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?
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.
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.
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.
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.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With