【发布时间】:2019-06-01 20:03:59
【问题描述】:
我正在使用 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
我该如何解决这个问题。
【问题讨论】:
-
为什么要手动启用 Web Flux?如果那在您的类路径上,Spring Boot 将自动启用它。这同样适用于 web mvc 部分。看起来您的类路径触发器上的
spring-webmvc和spring-webfluxjar 都需要配置。 -
好的。但是如果我想配置 WebFlux ,我该怎么做。通过启用 @EnableWebFlux 并从 WebFluxConfigurer.class 扩展?
-
你不需要
@EnableWebFlux,因为 Spring Boot 会自动为你做这件事。如果您想自定义配置,只需在您的项目中创建一个WebFluxConfigurer并添加一个@Configuration注释即可。 -
啊哈明白了,非常感谢
-
并且还要确保你的类路径中没有 web 和 WebFlux jar,否则 Spring Boot 将尝试同时配置这两者。正如您已经注意到的那样,这是不允许的。
标签: java spring-boot spring-mvc spring-webflux