Does not the spring-boot-starter-web and spring-boot-starter-webflux work together?

kenzhaoyihui :

When I start to learn the spring-webflux, I have the question about this component.

I builded the simple project, useing the maven to manage the project, and add the dependences about spring-boot-starter-web and spring-boot-starter-webflux", like :

    <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>

But it doesn't work. When removing the spring-boot-starter-web dependency, it can work well.

Brian Clozel :

As explained in the Spring Boot reference documentation section about WebFlux, adding both web and webflux starters will configure a Spring MVC web application.

This is behaving like that, because many existing Spring Boot web applications (using MVC) will depend on the webflux starter to use the WebClient. Spring MVC partially support reactive return types, so this is an expected use case. The opposite isn't really true, since a reactive application is not really likely to use Spring MVC bits.

So using both web and webflux starters is supported, but it will configure a Spring MVC application. You can always force the Spring Boot application to be reactive with:

SpringApplication.setWebApplicationType(WebApplicationType.REACTIVE)

But it's still a good idea to clean up dependencies as it would be easy to use a blocking feature in your reactive web application.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=68659&siteId=1