1
我正在使用「路由器Kotlin DSL」遷移到Spring WebFlux(和Spring Boot)的功能變體。現在我需要一些MIME類型爲multipart/form-data
而不是PUT
與application/json
一些數據。帶功能Webflux的文件上傳
當我定義了一個簡單的路由器功能和處理這樣我得到下面的堆棧跟蹤:
fun routes(handler: MultimediaHandler) = router {
(accept(MediaType.MULTIPART_FORM_DATA) and "/multimedia").nest {
PUT("/{id}", handler::upload)
}
}
class MultimediaHandler {
fun upload(request: ServerRequest): Mono<ServerResponse> {
val id = request.pathVariable("id")
return noContent().build()
}
}
堆棧跟蹤:
13:43:29.713 ERROR [i.u.request] [XNIO-1 I/O-3] UT005071: Undertow request failed HttpServerExchange{ PUT /multimedia/00000000-0000-0000-0000-000000000
001 request {Connection=[Keep-Alive], Accept-Encoding=[gzip,deflate], Content-Length=[1672], Content-Type=[multipart/form-data; boundary=-mJAzUqZoGk2nc
N1Rch4O4-KGbTExkAmQ7A], User-Agent=[Apache-HttpClient/4.5.2 (Java/1.8.0_144)], Host=[localhost:8444]} response {}}
java.lang.IllegalStateException: No multipart HttpMessageReader.
at org.springframework.web.server.adapter.DefaultServerWebExchange.lambda$initMultipartData$3(DefaultServerWebExchange.java:144) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at java.util.Optional.orElseThrow(Optional.java:290) ~[?:1.8.0_144]
at org.springframework.web.server.adapter.DefaultServerWebExchange.initMultipartData(DefaultServerWebExchange.java:144) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.web.server.adapter.DefaultServerWebExchange.<init>(DefaultServerWebExchange.java:109) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.web.server.adapter.HttpWebHandlerAdapter.createExchange(HttpWebHandlerAdapter.java:167) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.web.server.adapter.HttpWebHandlerAdapter.handle(HttpWebHandlerAdapter.java:156) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.http.server.reactive.UndertowHttpHandlerAdapter.handleRequest(UndertowHttpHandlerAdapter.java:71) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:332) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:254) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:136) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:148) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at io.undertow.server.protocol.http.AlpnOpenListener$AlpnConnectionListener.handleEvent(AlpnOpenListener.java:357) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at io.undertow.server.protocol.http.AlpnOpenListener$AlpnConnectionListener.handleEvent(AlpnOpenListener.java:308) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) [xnio-api-3.5.1.Final.jar:3.5.1.Final]
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66) [xnio-api-3.5.1.Final.jar:3.5.1.Final]
at io.undertow.protocols.ssl.SslConduit$SslReadReadyHandler.readReady(SslConduit.java:1140) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89) [xnio-nio-3.5.1.Final.jar:3.5.1.Final]
at org.xnio.nio.WorkerThread.run(WorkerThread.java:571) [xnio-nio-3.5.1.Final.jar:3.5.1.Final]
謝謝,現在錯誤消失了。僅供參考,只要我在Spring MVC中使用Spring Cloud和Spring Boot,就不需要這種依賴關係。我只用了@RequestParam的MultipartFile。 –
這是因爲它使用標準的servlet多部分支持。這裏沒有這樣的事情。 –