Can a Spring Cloud Feign client share interface with an Spring Web Controller?

后端 未结 1 1296
一向
一向 2020-12-14 04:48

Building an endpoint and client with Spring MVC and Feign Client (with spring cloud). I had the thought that since both ends need to have the same annotations - and that the

相关标签:
1条回答
  • 2020-12-14 04:53

    This is possible as of Feign 8.6.0. From the Spring Cloud docs:

    Feign Inheritance Support

    Feign supports boilerplate apis via single-inheritance interfaces. This allows grouping common operations into convenient base interfaces. Together with Spring MVC you can share the same contract for your REST endpoint and Feign client.

    UserService.java

    public interface UserService {
    
        @RequestMapping(method = RequestMethod.GET, value ="/users/{id}")
        User getUser(@PathVariable("id") long id);
    }
    

    UserResource.java

    @RestController
    public class UserResource implements UserService {
    
    }
    

    UserClient.java

    @FeignClient("users")
    public interface UserClient extends UserService {
    
    }
    
    0 讨论(0)
提交回复
热议问题