Open mariuszs opened 5 years ago
spring-cloud-gateway-mvc
is not compatible with gateway core. You need to use spring-cloud-gateway-webflux
.
Ok, maybe instead of putting this information in issue will be better to put this into documentation. Link -> https://cloud.spring.io/spring-cloud-gateway/multi/multi__building_a_simple_gateway_using_spring_mvc_or_webflux.html
We clearly state in the documentation that the core gateway is not compatible with MVC and there actually should be a warning in the logs stating such.
So this link is not part of this documentation?
but still Chapter 13 is broken and it is confusing a lot of people.
PRs welcome
We clearly state in the documentation that the core gateway is not compatible with MVC and there actually should be a warning in the logs stating such.
I didn't see this. So at least its not so easy to find. The message in the log, yes that's there:
Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency
However I don't want to remove the web starter, I do not want to go full on reactive and 'plain' MVC is what I actually want to use. So it would be nice to have some guidance from the docs, or from that log message on what can be used instead of spring-cloud-gateway that is compatible with Web MVC. I don't think it should be assumed that everyone should just start using reactive.
We made the decision at the beginning that the spring cloud gateway server would be webflux only. I don't know how we can be clearer than this
https://docs.spring.io/spring-cloud-gateway/docs/2.2.5.RELEASE/reference/html/#gateway-starter
I guess, yes it does say that in the second big 'bubble'. That is if we know that 'traditional servlet context' means 'web MVC'. Although for the somewhat inexperienced (like me :-)... it doesn't really directly say that gateway doesn't work with spring-web-starter or spring MVC.
I get confused because... I beleave it is possible to use the web client from webflux dependency in web mvc, so just saying that something is build on webflux doesn't immediately imply that it doesn't work with mvc, I think.
But, this is what really got me confused though:
This project provides a library for building an API Gateway on top of Spring MVC. Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross cutting concerns to them such as: security, monitoring/metrics, and resiliency.
That is right at the top of: https://spring.io/projects/spring-cloud-gateway
Also, if we can't use spring-cloud-gateway with webmvc, what options are there for something that you actually can use with it? That is really the question I'd like to get an answer to when I'm asking for "guidance". So, of course, it is totally fine to say I can't use 'gateway with mvc' and that is the decision that was made. However, then it would be nice to suggest an alternative for when not using MVC is simply not an option.
Yeah, not sure how we missed that bit at the top. It clearly shouldn't say built on mvc
There isn't an alternative
I discussed with the spring-cloud folks in slack about the use of reactor for gateway and alternatives for pure MVC. That discussion was educational to me and I think it would be good to summarize here for the public record.
First, in practice it probably doesn't matter much whether the gateway app is reactive or not reactive because:
a typical gateway app would be a 'standalone' gateway. There is hardly any code, (if any code at all) needed to configure it. So how the gateway is implemented under the hood matters very little to developer.
a less typical app, may wish to embed the gateway into another MVC style app. However making that MVC code run in a webflux environment instead of traditional MVC environment, should only come down to a depencency swap, no code changes.
Second, there is a short term alternative:
Finally, there is a related github ticket here https://github.com/spring-cloud/spring-cloud-gateway/issues/36 . People who feel strongly about needing gateway to be usable in a traditional MVC context can express their opinion by voting / commenting on that ticket.
Going through all this as a beginner, i still don't understand whether Cloud Gateway can be used as a proxy to Spring MVC services ? @kdvolder Could you provide the slack channel, for communicating about this in slack ?
Proxy MVC services is fine. Gateway can proxy anything, doesn't even have to be Java, just http. The gateway app itself can not be MVC
This is similar to #319 . Application created using http://start.spring.io with gateway dependency and with additional
spring-cloud-gateway-mvc
fails.If
spring-boot-starter-web
is not compatible, then what is the purpose of this dependency?Error:
Documentation: https://cloud.spring.io/spring-cloud-gateway/multi/multi__building_a_simple_gateway_using_spring_mvc_or_webflux.html