问题描述
查看ZuulConfiguration,看到如下:
@Bean
public ZuulController zuulController() {
return new ZuulController();
}
@Bean
public ServletRegistrationBean zuulServlet() {
return new ServletRegistrationBean(new ZuulServlet(),
this.zuulProperties.getServletPattern());
}
ZuulController 包装了 ZuulServlet 并像管理 Spring Controller 一样管理其生命周期.让我感到困惑的是 ZuulConfiguration 类无论如何都使用 ServletRegistrationBean 注册了 servlet.也许我的想法是错误的,但我认为你会做一个或另一个.有人能解释一下为什么两者都是必要的吗?
ZuulController wraps the ZuulServlet and manages its lifecycle as if it were a Spring Controller. What throws me is that the ZuulConfiguration class registers the servlet anyways using a ServletRegistrationBean. Perhaps I am thinking the wrong thing, but I would think that you would do one or the other. Could someone explain why both are necessary?
使用此配置,ZuulServlet 是作为真正的 servlet(被嵌入式 servlet 容器所知)、控制器(委托给 servlet)还是两者都运行?
Using this configuration, is the ZuulServlet running as a true servlet (known by the embedded servlet container), a controller (which delegates to the servlet) or both?
谢谢,
约书亚
推荐答案
来自 这次提交:
允许在 Zuul 代理中传输多部分请求
事实证明,Zuul 的多部分请求很糟糕几乎完全来自 Spring 中的 Multipart 处理调度程序小服务程序.此更改使代理路由可用在替代路径/zuul/(其中/zuul 是 zuul.servletPath 的默认值).我有使用中的 main 方法测试了那些具有 800MB 文件上传的文件FormZuulServletProxyApplicationTests 和主要的观察结果是没有 OutOfMemory 错误(没有人尝试下载完整的请求正文).它适用于功能区并使用简单的 (HttpClient) 过滤器.用丝带你如果你想上传文件,需要设置一些超时这么大,例如在测试中查看 application.yml:
It turns out that the suckiness of Zuul with multipart requestscomes almost entirely from the Multipart handling in Spring'sDispatcherServlet. This change makes the proxy routes availableon an alternative path /zuul/ (where/zuul is the default value of zuul.servletPath). I havetested those with 800MB file uploads using the main method inthe FormZuulServletProxyApplicationTests and the mainobservation is that there is no OutOfMemory error (no-one triesto download the complete request body). It works with Ribbonand with the simple (HttpClient) filter. With Ribbon youwill need to set some timeouts if you want to upload filesas large as that, e.g. see application.yml in the tests:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
ribbon:
ConnectTimeout: 3000
ReadTimeout: 60000
您需要在传入请求.默认情况下,Chrome 不会执行此操作显然,但我能够用 curl 进行测试,例如
You need to set "Transfer-Encoding: chunked" in theincoming request. Chrome does not do this by defaultapparently, but I was able to test with curl, e.g.
$ curl -v -H "Transfer-Encoding: chunked" \
-F "[email protected]" \
localhost:9999/zuul/direct/file
通过 DispatcherServlet 的旧代理路径仍然是可用(为了向后兼容和方便在上下文路径的根目录中有可用的路径).
The old proxy paths through the DispatcherServlet are stillavailable (for backwards compatibility and for convenience ofhaving the paths available at the root of the context path).
这篇关于Spring Cloud Netflix:使用 ZuulServlet 在 ZuulConfiguration 中发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!