首页 > 解决方案 > 带有 @EnableWebFlux 注释的 SpringWebFlux 错误

问题描述

我正在使用 spring boot 2.1.1 版本并使用@EnableWebFlux,但出现了一些错误。

错误是

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.reactive.config.DelegatingWebFluxConfiguration': Initialization of bean failed; nested exception is java.lang.IllegalStateException: The Java/XML config for Spring MVC and Spring WebFlux cannot both be enabled, e.g. via @EnableWebMvc and @EnableWebFlux, in the same application

我该如何解决这个问题。

标签: javaspring-bootspring-mvcspring-webflux

解决方案


您不能在Spring SPR-16609 中同时启用 Spring MVC 和 Spring WebFlux

在触发冲突的同一应用程序上下文中启用 MVC 和 WebFlux

你目前不能让它们在同一个过程中。

它提供了一种使用反应式存储库的解决方法:

但是,您可以使用现有 Spring MVC 应用程序中的响应式存储库,并从 Spring MVC 控制器方法返回响应式类型(Flux 或 Mono)。


推荐阅读