Reputation: 203
No matter how I set my project up I get the following exception on startup:
"Unsupported suspending handler method detected".
I'm trying to use the support for coroutines described in https://docs.spring.io/spring/docs/5.2.0.BUILD-SNAPSHOT/spring-framework-reference/languages.html#coroutines.
Here's my gradle setup up (abbreviated). How do I get rid of this exception?
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"
Upvotes: 3
Views: 2345
Reputation: 6209
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.
It usually happens when you are using spring-boot-starter-webflux
with a dependency (here springfox-swagger2
) that brings transitively Spring MVC in the classpath.
Setting spring.main.web-application-type=reactive
in your application.properties
(or the equivalent for application.yml
) will force using WebFlux server and probably avoid this issue.
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 what you want. 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.
Upvotes: 8
Reputation: 255
I had the same issue for a few hours here.
The way I solved this was by not using the @RequestMapping annotation.
Removing that annotation and moving the @RequestMapping values down the the @GetMapping and @PostMappings, etc worked. Not a good solution by any means, but the only one I've found so far.
It seems like the problem is coming from Spring MVC adding a check in the code for suspending funtions, which is shared with WebFlux I guess: https://github.com/spring-projects/spring-framework/issues/23585
Upvotes: 0