Spring Cloud Feign 客户端可以与 Spring Web 控制器共享接口吗?

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

使用 Spring MVC 和 Feign 客户端(使用 spring 云)构建端点和客户端。我的想法是,因为两端需要有相同的注释——而且它们必须非常同步。也许我可以在一个接口中定义它们并让两端实现它。

测试出来我有点惊讶它实际上适用于 Spring Web 端。

但是我找不到对 Feign 客户端执行相同操作的方法。

接口我基本都有:

@RequestMapping("/somebaseurl")
public interface ServiceInterface {
  @RequestMapping(value = "/resource/{identifier}", method = RequestMethod.POST)
  public SomeResource getResourceByIdentifier(String identifier);
}

然后是 RestController

@RestController
public class ServiceController implements ServiceInterface {
    public SomeResource getResourceByIdentifier(@PathVariable("identifier") String identifier) {
    // Do some stuff that gets the resource
        return new SomeResource();
    }
}

最后是 Feign Client

@FeignClient("serviceName")
public interface ServiceClient extends ServiceInterface {
}

Feign 客户端似乎没有读取继承的注解。那么有没有其他方法可以完成同样的事情?哪里可以不用直接注解把ServiceInterface做成Feign客户端?

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 {

}