spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.49k stars 3.3k forks source link

Document that spring-cloud-gateway-mvc is not compatible with spring-cloud-gateway-core #1004

Open mariuszs opened 5 years ago

mariuszs commented 5 years ago

This is similar to #319 . Application created using http://start.spring.io with gateway dependency and with additional spring-cloud-gateway-mvc fails.

 <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-gateway-mvc</artifactId>
  </dependency>

If spring-boot-starter-web is not compatible, then what is the purpose of this dependency?

Error:

Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' in your configuration.

Documentation: https://cloud.spring.io/spring-cloud-gateway/multi/multi__building_a_simple_gateway_using_spring_mvc_or_webflux.html

spencergibb commented 5 years ago

spring-cloud-gateway-mvc is not compatible with gateway core. You need to use spring-cloud-gateway-webflux.

mariuszs commented 5 years ago

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

spencergibb commented 5 years ago

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.

mariuszs commented 5 years ago

So this link is not part of this documentation?

https://cloud.spring.io/spring-cloud-gateway/multi/multi__building_a_simple_gateway_using_spring_mvc_or_webflux.html

spencergibb commented 5 years ago

https://cloud.spring.io/spring-cloud-gateway/multi/multi_gateway-starter.html

mariuszs commented 5 years ago

but still Chapter 13 is broken and it is confusing a lot of people.

spencergibb commented 5 years ago

PRs welcome

kdvolder commented 3 years ago

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.

spencergibb commented 3 years ago

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

kdvolder commented 3 years ago

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.

spencergibb commented 3 years ago

Yeah, not sure how we missed that bit at the top. It clearly shouldn't say built on mvc

spencergibb commented 3 years ago

There isn't an alternative

kdvolder commented 3 years ago

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:

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.

dimosian-nzia commented 1 year ago

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 ?

spencergibb commented 1 year ago

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