【发布时间】:2019-12-19 16:56:36
【问题描述】:
我有一个 Spring Webflux 应用程序,我正在尝试从旧模块加载依赖项(旧模块位于 Spring WebMVC 框架上)。
应用程序启动时,抛出此错误 -
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'requestMappingHandlerAdapter', defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
我希望启动 webflux 包中的所有 bean,所以我不能设置 spring.main.allow-bean-definition-overriding=true。
还尝试在组件扫描时排除 org.springframework.boot 中的所有类 - @ComponentScan(excludeFilters = @Filter(type = FilterType.REGEX, pattern = "org.springframework.boot*")。
还尝试像这样排除我的 webflux 项目的 pom.xml 中的所有 spring 包-
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
由于我无法将旧的依赖项目修改为 webflux,是否有任何选项可以使代码正常工作?
【问题讨论】:
标签: java spring spring-boot spring-mvc spring-webflux