ServiceComb如何支持通配符 **
在SpringBoot中,@RequestMapping("**")代表匹配任何路径,我的工程里将/symbol/**的所有请求进行了统一处理。但 serviceComb不支持 **,原因是org.apache.servicecomb.common.rest.definition.path.PathRegExp会将 ** compile,而这种写法在正则表达式里是错误的。servicecomb是否有办法让@RequestMapping同时匹配多级目录,如"test"和"test/test1"
参考 https://github.com/apache/servicecomb-java-chassis/issues/2329
参考 #2329
@RequestMapping(path = {"/{path:.+}"}, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<byte[]> catchAll(@PathVariable String path, HttpServletRequest request)
throws IOException {
System.out.println(path);
}
这种修改方式已经尝试过,我在这里用过 .+ 和 .* ,问题在于没法匹配多级路径,只可以匹配一级路径,如 /hello可以匹配, /hello/test无法匹配
参考 #2329
@RequestMapping(path = {"/{path:.+}"}, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<byte[]> catchAll(@PathVariable String path, HttpServletRequest request) throws IOException { System.out.println(path); }这种修改方式已经尝试过,我在这里用过 .+ 和 .* ,问题在于没法匹配多级路径,只可以匹配一级路径,如 /hello可以匹配, /hello/test无法匹配
也没有改过什么,就突然可以用了
参考 #2329
@RequestMapping(path = {"/{path:.+}"}, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<byte[]> catchAll(@PathVariable String path, HttpServletRequest request) throws IOException { System.out.println(path); }这种修改方式已经尝试过,我在这里用过 .+ 和 .* ,问题在于没法匹配多级路径,只可以匹配一级路径,如 /hello可以匹配, /hello/test无法匹配
也没有改过什么,就突然可以用了
在配置文件里,servicecomb.rest.address的端口号与spring设置的端口号不同时,可以匹配/hello,无法匹配/hello/test,而端口号一致时可以匹配两者。不知道是什么原因
参考 #2329
@RequestMapping(path = {"/{path:.+}"}, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<byte[]> catchAll(@PathVariable String path, HttpServletRequest request) throws IOException { System.out.println(path); }这种修改方式已经尝试过,我在这里用过 .+ 和 .* ,问题在于没法匹配多级路径,只可以匹配一级路径,如 /hello可以匹配, /hello/test无法匹配
也没有改过什么,就突然可以用了
在配置文件里,servicecomb.rest.address的端口号与spring设置的端口号不同时,可以匹配/hello,无法匹配/hello/test,而端口号一致时可以匹配两者。不知道是什么原因
https://servicecomb.apache.org/references/java-chassis/zh_CN/spring-boot/introduction.html 两个的差异可以参考这个说明。 估计vert.x容器还没支持到你说的场景,不过得验证下。
参考 #2329
@RequestMapping(path = {"/{path:.+}"}, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<byte[]> catchAll(@PathVariable String path, HttpServletRequest request) throws IOException { System.out.println(path); }这种修改方式已经尝试过,我在这里用过 .+ 和 .* ,问题在于没法匹配多级路径,只可以匹配一级路径,如 /hello可以匹配, /hello/test无法匹配
也没有改过什么,就突然可以用了
在配置文件里,servicecomb.rest.address的端口号与spring设置的端口号不同时,可以匹配/hello,无法匹配/hello/test,而端口号一致时可以匹配两者。不知道是什么原因
https://servicecomb.apache.org/references/java-chassis/zh_CN/spring-boot/introduction.html 两个的差异可以参考这个说明。 估计vert.x容器还没支持到你说的场景,不过得验证下。
我验证了好几次,配置文件里server.port与servicecomb.rest.address的端口号不一致时,会导致单层请求成功,多层失败。虽然这两个端口一般是保持一致的,但我正好要测试一下不同端口的转发情况,所以遇到了这个问题。 server.port是8088,servicecomb.rest.address是 0.0.0.0:8087
参考 #2329
@RequestMapping(path = {"/{path:.+}"}, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<byte[]> catchAll(@PathVariable String path, HttpServletRequest request) throws IOException { System.out.println(path); }这种修改方式已经尝试过,我在这里用过 .+ 和 .* ,问题在于没法匹配多级路径,只可以匹配一级路径,如 /hello可以匹配, /hello/test无法匹配
也没有改过什么,就突然可以用了
在配置文件里,servicecomb.rest.address的端口号与spring设置的端口号不同时,可以匹配/hello,无法匹配/hello/test,而端口号一致时可以匹配两者。不知道是什么原因
https://servicecomb.apache.org/references/java-chassis/zh_CN/spring-boot/introduction.html 两个的差异可以参考这个说明。 估计vert.x容器还没支持到你说的场景,不过得验证下。
我验证了好几次,配置文件里server.port与servicecomb.rest.address的端口号不一致时,会导致单层请求成功,多层失败。虽然这两个端口一般是保持一致的,但我正好要测试一下不同端口的转发情况,所以遇到了这个问题。 server.port是8088,servicecomb.rest.address是 0.0.0.0:8087
端口号不同的情况,你使用的8088端口请求的还是8087端口请求的?我测试了 servlet 和 vertx 两种场景都是正常的。 参考代码 。 怀疑你使用了8088端口,这个是不正确的,这种情况就和java chassis没关系了。