簡體   English   中英

Spring WebFlux Reactive 和 Kotlin 協程啟動錯誤

[英]Spring WebFlux Reactive and Kotlin Coroutines Startup Error

無論我如何設置我的項目,我都會在啟動時遇到以下異常:

“檢測到不支持的掛起處理程序方法”。

我正在嘗試使用對https://docs.spring.io/spring/docs/5.2.0.BUILD-SNAPSHOT/spring-framework-reference/languages.html#coroutines中描述的協程的支持。

這是我的 gradle 設置(縮寫)。 我如何擺脫這個異常?

ext.kotlin_version = '1.3.70'
ext.kotlin_coroutines_core = '1.3.5'
ext.kotlin_coroutines_reactor = '1.3.5'
ext.spring_boot_version = '2.2.6.RELEASE'
ext.springfox_version='2.9.2'
ext.jackson_module_kotlin = '2.10.3'
...

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_core"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlin_coroutines_reactor"
implementation "org.springframework.boot:spring-boot-starter-webflux:$spring_boot_version"
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:$jackson_module_kotlin"
implementation "net.rakugakibox.spring.boot:logback-access-spring-boot-starter:2.7.1"
implementation "net.logstash.logback:logstash-logback-encoder:5.3"
implementation "org.springframework.boot:spring-boot-starter-actuator:$spring_boot_version"
implementation "io.micrometer:micrometer-registry-statsd:1.1.4"
implementation "io.springfox:springfox-swagger2:$springfox_version"

This probably happens because when there are both Spring MVC and Spring WebFlux in the classpath, Spring MVC server is used by Spring Boot because Spring WebFlux also contains the WebClient that can be used with both servers.

當您使用帶有依賴項(此處springfox-swagger2spring-boot-starter-webflux時,通常會發生這種情況,該依賴項會在類路徑中傳遞 Spring MVC。

application.properties (或application.yml的等效項)中設置spring.main.web-application-type=reactive將強制使用 WebFlux 服務器並可能避免此問題。

Notice that Spring MVC supports Coroutines as well (using internally MVC async support) as of Spring Framework 5.3 and Spring Boot 2.4 so with those versions you will not have this error, but you will have Spring MVC used instead of Spring WebFlux which is probably not你想要什么。 So even with Spring Boot 2.4+ you should set spring.main.web-application-type=reactive if you want to use Spring WebFlux with a dependency that pulls transitively Spring MVC.

我在這里有幾個小時同樣的問題。

我解決這個問題的方法是不使用 @RequestMapping 注釋。

刪除該注釋並將@RequestMapping 值向下移動到@GetMapping 和@PostMappings 等工作。 無論如何都不是一個好的解決方案,但到目前為止我發現的唯一一個。

似乎問題來自 Spring MVC,在代碼中添加了暫停功能的檢查,我猜這是與 WebFlux 共享的: https://github.com/spring-projects/spring-framework/issues/23585

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM