Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring mvc and webflux in 1 spring boot application

I got below instruction from spring boot doc:

Adding both spring-boot-starter-web and spring-boot-starter-webflux modules in your application results in Spring Boot auto-configuring Spring MVC, not WebFlux. This behavior has been chosen because many Spring developers add spring-boot-starter-webflux to their Spring MVC application to use the reactive WebClient. You can still enforce your choice by setting the chosen application type to SpringApplication.setWebApplicationType(WebApplicationType.REACTIVE)

My question is:

What if my application contains both MVC services and webflux services? Is it supported?

For example:

I may have some existing admin service which is MVC based. Now I want to add some new services with webflux style.

like image 980
anuni Avatar asked May 21 '18 15:05

anuni


People also ask

Can I use spring MVC and WebFlux together?

As explained in the Spring Boot reference documentation, Spring Boot will auto-configure a Spring MVC application if both MVC and WebFlux are available.

Can we use spring MVC and Spring boot together?

Yes, you can use Spring MVC with Spring Boot. To create and run a Spring MVC web application in spring boot, you need to add the spring-boot-starter dependency in your pom. xml file.

Is WebFlux part of spring boot?

Spring 5 includes Spring WebFlux, which provides reactive programming support for web applications.

What is the difference between spring MVC and spring WebFlux?

Moreover, Spring WebFlux supports reactive backpressure, so we have more control over how we should react to fast producers than both Spring MVC Async and Spring MVC. Spring Flux also has a tangible shift towards functional coding style and declarative API decomposition thanks to Reactor API behind it.


1 Answers

No, this is not supported. Spring MVC and Spring WebFlux have different runtime models and don't support the same servers (for example, Spring WebFlux can be run with Netty, Spring MVC cannot).

Also, Spring MVC and Spring WebFlux are full web frameworks, meaning each has its own infrastructure that somehow duplicates the other. Deploying both in the same app would make it difficult to map requests (which requests should go where?).

like image 118
Brian Clozel Avatar answered Sep 23 '22 13:09

Brian Clozel