servicecomb-java-chassis icon indicating copy to clipboard operation
servicecomb-java-chassis copied to clipboard

@EnableServiceComb 注解如何更改SpringBoot项目的运行逻辑

Open Welkin1027 opened this issue 2 years ago • 1 comments

目前在将一个Springboot项目添加Servicecomb微服务。目前有一个问题,SpringBoot项目中,导出文件需要用到HttpServletResponse,但Servicecomb不支持HttpServletResponse,因此按照文档说明里提到的FilePart类型来下载文件。调用接口时,发生Error:not supported method。我将这个方法移植到另一个新开发的springboot+servicecomb项目,是可以成功下载文件的。 具体方法如下:

@RequestMapping(value = "/file/downloadPart", method = RequestMethod.GET)
    @ApiResponses({@ApiResponse(code = 200, response = File.class, message = "")})
    public FilePart downloadFilePart(@RequestParam(value = "fileId") String fileId) throws FileNotFoundException {
        FilePart filePart = new FilePart(null, new File("test.txt"));
        return filePart;
    }

我分步调试的时候发现,原始的Springboot项目在接到请求时,优先调用了org.springframework.web.method.support.InvocableHandlerMethod里的doInvoke方法;而新开发的项目则是优先调用了org.apache.servicecomb.common.rest.filter.inner.ServerRestArgsFilter的afterReceiveRequest方法,并且没有调用InvocableHandlerMethod的doInvoke方法,而是调用了org.apache.servicecomb.core.handler.impl.ProducerOperationHandler的doInvoke方法。

我将新项目的@EnableServiceComb注解注释掉之后,发现新项目也和原始项目一样调用了InvocableHandlerMethod的doInvoke方法,并且报出了和原始项目相同的错误。我推测的是,@EnableServiceComb注解能够改变SpringBoot项目的调用逻辑,走了ServerRestArgsFilter和ProducerOperationHandler。但这个注解并没有成功修改原始的SpringBoot项目的调用逻辑,所以想咨询一下原因。

PS:我已经将原始SpringBoot项目里自带的Filter文件都注释掉了。两个项目使用的springboot都是2.3.0.RELEASE版本,servicecomb则是2.8.9版本

Welkin1027 avatar Mar 14 '24 08:03 Welkin1027

具体可以参考你前面提的问题: https://github.com/apache/servicecomb-java-chassis/issues/4263

上传下载参考: https://servicecomb.apache.org/references/java-chassis/zh_CN/general-development/upload-download.html

liubao68 avatar Mar 15 '24 14:03 liubao68