Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better failure analysis when Gateway is embedded in a MVC app #2176

Closed
snicoll opened this issue Mar 10, 2021 · 3 comments
Closed

Better failure analysis when Gateway is embedded in a MVC app #2176

snicoll opened this issue Mar 10, 2021 · 3 comments
Assignees
Labels
Milestone

Comments

@snicoll
Copy link

snicoll commented Mar 10, 2021

Is your feature request related to a problem? Please describe.
With Spring MVC being the most popular option to build spring web apps, users are likely to try using this project in combination with Spring MVC (spring-boot-starter-web specifically). The fact that this project brings Spring Webflux does not matter unfortunately as Spring Boot starts up in Servlet mode when both web and webflux are on the classpath.

While this is an invalid combination, the failure analysis on startup is too low level and doesn't indicate to the user what is wrong with their setup:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found.


Action:

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

This looks like an oversight of a more general approach as starting the app with a more narrowed web application type leads to:


**********************************************************

Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.

**********************************************************

Describe the solution you'd like
Backing off completely sounds heading in the opposite direction given users opting-in for this project. Perhaps the auto-configuration could have a check on MVC and throw a dedicated exception? This exception can have a dedicated failure analyzer that would provide a more precise explanation about the setup and why it is invalid.

An action could be that spring.main.web-application-type should be set to reactive. However, given the warning above, that doesn't sound great so for consistency I guess we should ask the user to remove the dependency.

Describe alternatives you've considered
Backing off completely doesn't sound like a good idea.

Additional context
spring-io/start.spring.io#653

@spencergibb spencergibb added this to To do in Hoxton.SR11 via automation Mar 19, 2021
@spencergibb spencergibb added this to To do in 2020.0.3 via automation Mar 19, 2021
@spencergibb spencergibb self-assigned this Apr 19, 2021
@spencergibb spencergibb moved this from To do to In progress in Hoxton.SR11 Apr 19, 2021
@spencergibb spencergibb moved this from To do to In progress in 2020.0.3 Apr 19, 2021
@spencergibb spencergibb added this to the 2.2.8.RELEASE milestone Apr 19, 2021
Hoxton.SR11 automation moved this from In progress to Done Apr 19, 2021
2020.0.3 automation moved this from In progress to Done Apr 19, 2021
spencergibb added a commit that referenced this issue Apr 20, 2021
This is useful for libraries that might write functionality for zuul and gateway.

See gh-2176
@snicoll
Copy link
Author

snicoll commented Apr 20, 2021

Thanks for the update @spencergibb. I believe this change is a bit too broad, especially considering that Spring Boot supports starting a reactive web server even if Spring MVC is present on the classpath.

With Spring Cloud 2020.0.2, having both MVC and WebFlux on the classpath isn't a problem as long as the user has opt-in for WebFlux using spring.main.web-application-type=reactive.

With Spring Cloud 2020.0.3-SNAPSHOT and the same setup, I get:

***************************
APPLICATION FAILED TO START
***************************

Description:

Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway.

Action:

Please remove spring-boot-starter-web dependency.

With this change, the only solutions I found are to remove Spring MVC or disable Spring Cloud Gateway. Was this intended?

@spencergibb
Copy link
Member

Gateway has narrower constraints than a general boot app (doesn't support tomcat yet for example). I can add setting the type to reactive as a suggestion, assuming it works (will need to test it).

@spencergibb
Copy link
Member

Done. See 2be9d7f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
2020.0.3
  
Done
Hoxton.SR11
  
Done
Development

No branches or pull requests

2 participants