Skip to content

Commit 32faf09

Browse files
committed
Add check for mixing @EnableWebMvc and @EnableWebFlux
Issue: SPR-16609
1 parent 0be8c20 commit 32faf09

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.springframework.beans.BeanUtils;
2626
import org.springframework.beans.factory.BeanInitializationException;
27+
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2728
import org.springframework.context.ApplicationContext;
2829
import org.springframework.context.ApplicationContextAware;
2930
import org.springframework.context.annotation.Bean;
@@ -38,6 +39,7 @@
3839
import org.springframework.format.support.FormattingConversionService;
3940
import org.springframework.http.codec.ServerCodecConfigurer;
4041
import org.springframework.lang.Nullable;
42+
import org.springframework.util.Assert;
4143
import org.springframework.util.ClassUtils;
4244
import org.springframework.validation.Errors;
4345
import org.springframework.validation.MessageCodesResolver;
@@ -93,13 +95,27 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
9395
@Override
9496
public void setApplicationContext(@Nullable ApplicationContext applicationContext) {
9597
this.applicationContext = applicationContext;
98+
assertWebMvcNotEnabled(applicationContext);
9699
}
97100

98101
@Nullable
99102
public final ApplicationContext getApplicationContext() {
100103
return this.applicationContext;
101104
}
102105

106+
private static void assertWebMvcNotEnabled(@Nullable ApplicationContext applicationContext) {
107+
try {
108+
if (applicationContext != null) {
109+
Assert.isNull(applicationContext.getType("mvcContentNegotiationManager"),
110+
"The Java/XML config for Spring MVC and Spring WebFlux cannot both be enabled, " +
111+
"e.g. via @EnableWebMvc and @EnableWebFlux, in the same application.");
112+
}
113+
}
114+
catch (NoSuchBeanDefinitionException ex) {
115+
// Expected...
116+
}
117+
}
118+
103119

104120
@Bean
105121
public DispatcherHandler webHandler() {

0 commit comments

Comments
 (0)