We have a number of Spring-Boot applications that are built via Gradle and all have subtly different spring dependencies.
When trying to copy code between the two of them, I am highly suspicious that I'm seeing problems due to the donor service using Spring MVC and the new service using Spring WebFlux.
Is there a "simple" way to check which stack has been loaded? I've seen documentation implying that if both are present then it'll default to MVC, but short of deep diving all the dependencies I'm not sure how to check that.
I've checked the logs, and it doesn't say anything about which stack is being used.
Is there a way to query which stack (MVC or WebFlux) is being loaded at runtime? Something which can be enabled in logging, or a Bean that will only be loaded by one or the other?
Edit: to clarify - the initial responses talk about spring-boot-starter-web
or spring-boot-starter-webflux
. In my case it turns out that it was spring-boot-starter-gateway
(which happens to work on WebFlux). Given that this is a case where it isn't immediately obvious dependencies and I've more than once seen people import both because they didn't know any better, I'm actually looking for a way to check which stack is being loaded at run-time without having to guess from the dependencies.
CodePudding user response:
You can check the gradle file. if it uses spring-boot-starter-webflux, the stack is webflux. if it uses spring-boot-starter-web, the stack is mvc.
spring-boot-starter-web build.gradle
plugins {
id "org.springframework.boot.starter"
}
description = "Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container"
dependencies {
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter"))
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-json"))
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-tomcat"))
api("org.springframework:spring-web")
api("org.springframework:spring-webmvc")
}
spring-boot-starter-webflux build.gradle
plugins {
id "org.springframework.boot.starter"
}
description = "Starter for building WebFlux applications using Spring Framework's Reactive Web support"
dependencies {
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter"))
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-json"))
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-reactor-netty"))
api("org.springframework:spring-web")
api("org.springframework:spring-webflux")
api("org.synchronoss.cloud:nio-multipart-parser")
}
CodePudding user response:
Thanks to M. Deinum for the pointer to --debug
.
In the end I managed to run the application with the --debug
flag.
Initially for me that resulted in a dump of JSON messages which I needed to pass through jq '.["message"]' --raw-output
in order to get something with useful formatting.
Then, on an educated guess I'd say that these were pretty conclusive:
In the WebFlux app:
WebFluxAutoConfiguration matched:
- @ConditionalOnClass found required class 'org.springframework.web.reactive.config.WebFluxConfigurer' (OnClassCondition)
- found ConfigurableReactiveWebEnvironment (OnWebApplicationCondition)
- @ConditionalOnMissingBean (types: org.springframework.web.reactive.config.WebFluxConfigurationSupport; SearchStrategy: all) did not find any beans (OnBeanCondition)
WebMvcAutoConfiguration:
Did not match:
- @ConditionalOnClass did not find required class 'javax.servlet.Servlet' (OnClassCondition)
In the WebMVC app:
WebMvcAutoConfiguration matched:
- @ConditionalOnClass found required classes 'javax.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet', 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer' (OnClassCondition)
- found 'session' scope (OnWebApplicationCondition)
- @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) did not find any beans (OnBeanCondition)
WebFluxAutoConfiguration:
Did not match:
- @ConditionalOnClass did not find required class 'org.springframework.web.reactive.config.WebFluxConfigurer' (OnClassCondition)