Search code examples
spring-bootspring-cloud-feignrequest-mapping

@RequestMapping annotation not allowed on @FeignClient interfaces


I'm having trouble with this! As I've been reading, it happens because it's no longer accepted. But how can I solved it? This is the code I've been trying to map.

@FeignClient(name = "product-service")
@RequestMapping("api/products/")
public interface ProductClient {

    @GetMapping("/{id}")
    ResponseEntity<Product> getProduct(@PathVariable("id") Long id);

    @GetMapping("/{id}/stock")
    ResponseEntity<Product> updateStockProduct(@PathVariable("id") Long id,@RequestParam(name = "quantity", required = true) Integer quantity);
}

Thanks in advance for any suggestion or solution!


Solution

  • You can use the path attribute of @FeignClient to define the path prefix to be added to all the APIs. The documentation is here.

    So your Feign client interface would look like

    @FeignClient(name = "product-service", path = "/api/products")
    public interface ProductClient {
    
        @GetMapping("/{id}")
        ResponseEntity<Product> getProduct(@PathVariable("id") Long id);
    
        @GetMapping("/{id}/stock")
        ResponseEntity<Product> updateStockProduct(@PathVariable("id") Long id,@RequestParam(name = "quantity", required = true) Integer quantity);
    }