首页 > 解决方案 > 如何使用带有 @PathVariable 的 Spring RemoteExporter

问题描述

我有一个(RPC)服务,我正在使用RemoteExporter如下所示:

@Service
public class FooService {
  // some operations here
}

@Configuration
public class RpcConfiguration {
  @Bean("/foo.rpc")
  RemoteExporter fooService(FooService foo) {
    // create and return the exporter here
  }
}

一切正常。现在我想在路径下公开服务/foo/{fooId}/bar.rpc(而不是/foo.rpc)。我认为RemoteExporter不理解路径变量(fooId)很好,只要我可以在路径下公开它/foo/*/bar.rpc(我将自己在导出器中提取路径变量)。
有没有办法在 Spring (Boot) 中做到这一点,最好没有 XML 的东西?谢谢。

标签: springspring-bootspring-mvc

解决方案


事实证明它比我想象的要聪明得多。只需使用问题中给出的模式作为 bean 名称!‍♂️</p>


推荐阅读