Home > Net >  When should I use starter web and starter webflux dependency in Spring Boot?
When should I use starter web and starter webflux dependency in Spring Boot?

Time:01-19

starter web and starter webflux dependency in Spring Boot. I am fall in dilemma. Please let me know what is the differences both of these. When, how, where should I used it? how to CRUD using both, starter web and starter webflux dependency? I am very new in this platform.

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency> 

I cannot understand it. so how to do this?

CodePudding user response:

The difference is that Spring Web MVC (spring-boot-starter-web) uses a synchronous programming model and Spring WebFlux (spring-boot-starter-webflux) uses an asynchronous (reactive) model.

The synchronous model uses a Java thread for each request and all method calls run synchronously in this thread returning the objects directly.

The asynchronous model uses reactive programming and each method call in a single request may be handled in different threads. The methods you write have to be non-blocking and return instances Mono or Flux.

I would recommend to start with Web MVC and the synchronous model as it is a lot easier to code and debug.

Spring MVC Async vs Spring WebFlux gives a more detailed comparison.

  • Related