|
24 | 24 |
|
25 | 25 | import org.springframework.beans.BeanUtils;
|
26 | 26 | import org.springframework.beans.factory.BeanInitializationException;
|
| 27 | +import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
27 | 28 | import org.springframework.context.ApplicationContext;
|
28 | 29 | import org.springframework.context.ApplicationContextAware;
|
29 | 30 | import org.springframework.context.annotation.Bean;
|
|
38 | 39 | import org.springframework.format.support.FormattingConversionService;
|
39 | 40 | import org.springframework.http.codec.ServerCodecConfigurer;
|
40 | 41 | import org.springframework.lang.Nullable;
|
| 42 | +import org.springframework.util.Assert; |
41 | 43 | import org.springframework.util.ClassUtils;
|
42 | 44 | import org.springframework.validation.Errors;
|
43 | 45 | import org.springframework.validation.MessageCodesResolver;
|
@@ -93,13 +95,27 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
93 | 95 | @Override
|
94 | 96 | public void setApplicationContext(@Nullable ApplicationContext applicationContext) {
|
95 | 97 | this.applicationContext = applicationContext;
|
| 98 | + assertWebMvcNotEnabled(applicationContext); |
96 | 99 | }
|
97 | 100 |
|
98 | 101 | @Nullable
|
99 | 102 | public final ApplicationContext getApplicationContext() {
|
100 | 103 | return this.applicationContext;
|
101 | 104 | }
|
102 | 105 |
|
| 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 | + |
103 | 119 |
|
104 | 120 | @Bean
|
105 | 121 | public DispatcherHandler webHandler() {
|
|
0 commit comments