Merge branch '2.3.x'

Closes gh-24016
pull/24020/head
Andy Wilkinson 4 years ago
commit f4e90f4512

@ -266,18 +266,22 @@ public class WebFluxAutoConfiguration {
@Override @Override
protected RequestMappingHandlerAdapter createRequestMappingHandlerAdapter() { protected RequestMappingHandlerAdapter createRequestMappingHandlerAdapter() {
if (this.webFluxRegistrations != null if (this.webFluxRegistrations != null) {
&& this.webFluxRegistrations.getRequestMappingHandlerAdapter() != null) { RequestMappingHandlerAdapter adapter = this.webFluxRegistrations.getRequestMappingHandlerAdapter();
return this.webFluxRegistrations.getRequestMappingHandlerAdapter(); if (adapter != null) {
return adapter;
}
} }
return super.createRequestMappingHandlerAdapter(); return super.createRequestMappingHandlerAdapter();
} }
@Override @Override
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() { protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
if (this.webFluxRegistrations != null if (this.webFluxRegistrations != null) {
&& this.webFluxRegistrations.getRequestMappingHandlerMapping() != null) { RequestMappingHandlerMapping mapping = this.webFluxRegistrations.getRequestMappingHandlerMapping();
return this.webFluxRegistrations.getRequestMappingHandlerMapping(); if (mapping != null) {
return mapping;
}
} }
return super.createRequestMappingHandlerMapping(); return super.createRequestMappingHandlerMapping();
} }

@ -405,8 +405,11 @@ public class WebMvcAutoConfiguration {
@Override @Override
protected RequestMappingHandlerAdapter createRequestMappingHandlerAdapter() { protected RequestMappingHandlerAdapter createRequestMappingHandlerAdapter() {
if (this.mvcRegistrations != null && this.mvcRegistrations.getRequestMappingHandlerAdapter() != null) { if (this.mvcRegistrations != null) {
return this.mvcRegistrations.getRequestMappingHandlerAdapter(); RequestMappingHandlerAdapter adapter = this.mvcRegistrations.getRequestMappingHandlerAdapter();
if (adapter != null) {
return adapter;
}
} }
return super.createRequestMappingHandlerAdapter(); return super.createRequestMappingHandlerAdapter();
} }
@ -491,8 +494,11 @@ public class WebMvcAutoConfiguration {
@Override @Override
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() { protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
if (this.mvcRegistrations != null && this.mvcRegistrations.getRequestMappingHandlerMapping() != null) { if (this.mvcRegistrations != null) {
return this.mvcRegistrations.getRequestMappingHandlerMapping(); RequestMappingHandlerMapping mapping = this.mvcRegistrations.getRequestMappingHandlerMapping();
if (mapping != null) {
return mapping;
}
} }
return super.createRequestMappingHandlerMapping(); return super.createRequestMappingHandlerMapping();
} }
@ -510,8 +516,12 @@ public class WebMvcAutoConfiguration {
@Override @Override
protected ExceptionHandlerExceptionResolver createExceptionHandlerExceptionResolver() { protected ExceptionHandlerExceptionResolver createExceptionHandlerExceptionResolver() {
if (this.mvcRegistrations != null && this.mvcRegistrations.getExceptionHandlerExceptionResolver() != null) { if (this.mvcRegistrations != null) {
return this.mvcRegistrations.getExceptionHandlerExceptionResolver(); ExceptionHandlerExceptionResolver resolver = this.mvcRegistrations
.getExceptionHandlerExceptionResolver();
if (resolver != null) {
return resolver;
}
} }
return super.createExceptionHandlerExceptionResolver(); return super.createExceptionHandlerExceptionResolver();
} }

@ -388,16 +388,20 @@ class WebFluxAutoConfigurationTests {
@Test @Test
void customRequestMappingHandlerMapping() { void customRequestMappingHandlerMapping() {
this.contextRunner.withUserConfiguration(CustomRequestMappingHandlerMapping.class) this.contextRunner.withUserConfiguration(CustomRequestMappingHandlerMapping.class).run((context) -> {
.run((context) -> assertThat(context).getBean(RequestMappingHandlerMapping.class) assertThat(context).getBean(RequestMappingHandlerMapping.class)
.isInstanceOf(MyRequestMappingHandlerMapping.class)); .isInstanceOf(MyRequestMappingHandlerMapping.class);
assertThat(context.getBean(CustomRequestMappingHandlerMapping.class).handlerMappings).isEqualTo(1);
});
} }
@Test @Test
void customRequestMappingHandlerAdapter() { void customRequestMappingHandlerAdapter() {
this.contextRunner.withUserConfiguration(CustomRequestMappingHandlerAdapter.class) this.contextRunner.withUserConfiguration(CustomRequestMappingHandlerAdapter.class).run((context) -> {
.run((context) -> assertThat(context).getBean(RequestMappingHandlerAdapter.class) assertThat(context).getBean(RequestMappingHandlerAdapter.class)
.isInstanceOf(MyRequestMappingHandlerAdapter.class)); .isInstanceOf(MyRequestMappingHandlerAdapter.class);
assertThat(context.getBean(CustomRequestMappingHandlerAdapter.class).handlerAdapters).isEqualTo(1);
});
} }
@Test @Test
@ -646,12 +650,15 @@ class WebFluxAutoConfigurationTests {
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
static class CustomRequestMappingHandlerAdapter { static class CustomRequestMappingHandlerAdapter {
private int handlerAdapters = 0;
@Bean @Bean
WebFluxRegistrations webFluxRegistrationsHandlerAdapter() { WebFluxRegistrations webFluxRegistrationsHandlerAdapter() {
return new WebFluxRegistrations() { return new WebFluxRegistrations() {
@Override @Override
public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() { public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() {
CustomRequestMappingHandlerAdapter.this.handlerAdapters++;
return new WebFluxAutoConfigurationTests.MyRequestMappingHandlerAdapter(); return new WebFluxAutoConfigurationTests.MyRequestMappingHandlerAdapter();
} }
@ -674,12 +681,15 @@ class WebFluxAutoConfigurationTests {
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
static class CustomRequestMappingHandlerMapping { static class CustomRequestMappingHandlerMapping {
private int handlerMappings = 0;
@Bean @Bean
WebFluxRegistrations webFluxRegistrationsHandlerMapping() { WebFluxRegistrations webFluxRegistrationsHandlerMapping() {
return new WebFluxRegistrations() { return new WebFluxRegistrations() {
@Override @Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() { public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
CustomRequestMappingHandlerMapping.this.handlerMappings++;
return new MyRequestMappingHandlerMapping(); return new MyRequestMappingHandlerMapping();
} }

@ -104,6 +104,7 @@ import org.springframework.web.servlet.handler.HandlerExceptionResolverComposite
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
import org.springframework.web.servlet.i18n.FixedLocaleResolver; import org.springframework.web.servlet.i18n.FixedLocaleResolver;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;
@ -553,16 +554,28 @@ class WebMvcAutoConfigurationTests {
@Test @Test
void customRequestMappingHandlerMapping() { void customRequestMappingHandlerMapping() {
this.contextRunner.withUserConfiguration(CustomRequestMappingHandlerMapping.class) this.contextRunner.withUserConfiguration(CustomRequestMappingHandlerMapping.class).run((context) -> {
.run((context) -> assertThat(context).getBean(RequestMappingHandlerMapping.class) assertThat(context).getBean(RequestMappingHandlerMapping.class)
.isInstanceOf(MyRequestMappingHandlerMapping.class)); .isInstanceOf(MyRequestMappingHandlerMapping.class);
assertThat(context.getBean(CustomRequestMappingHandlerMapping.class).handlerMappings).isEqualTo(1);
});
} }
@Test @Test
void customRequestMappingHandlerAdapter() { void customRequestMappingHandlerAdapter() {
this.contextRunner.withUserConfiguration(CustomRequestMappingHandlerAdapter.class) this.contextRunner.withUserConfiguration(CustomRequestMappingHandlerAdapter.class).run((context) -> {
.run((context) -> assertThat(context).getBean(RequestMappingHandlerAdapter.class) assertThat(context).getBean(RequestMappingHandlerAdapter.class)
.isInstanceOf(MyRequestMappingHandlerAdapter.class)); .isInstanceOf(MyRequestMappingHandlerAdapter.class);
assertThat(context.getBean(CustomRequestMappingHandlerAdapter.class).handlerAdapters).isEqualTo(1);
});
}
@Test
void customExceptionHandlerExceptionResolver() {
this.contextRunner.withUserConfiguration(CustomExceptionHandlerExceptionResolver.class)
.run((context) -> assertThat(
context.getBean(CustomExceptionHandlerExceptionResolver.class).exceptionResolvers)
.isEqualTo(1));
} }
@Test @Test
@ -1085,12 +1098,15 @@ class WebMvcAutoConfigurationTests {
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
static class CustomRequestMappingHandlerMapping { static class CustomRequestMappingHandlerMapping {
private int handlerMappings;
@Bean @Bean
WebMvcRegistrations webMvcRegistrationsHandlerMapping() { WebMvcRegistrations webMvcRegistrationsHandlerMapping() {
return new WebMvcRegistrations() { return new WebMvcRegistrations() {
@Override @Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() { public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
CustomRequestMappingHandlerMapping.this.handlerMappings++;
return new MyRequestMappingHandlerMapping(); return new MyRequestMappingHandlerMapping();
} }
@ -1106,12 +1122,15 @@ class WebMvcAutoConfigurationTests {
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
static class CustomRequestMappingHandlerAdapter { static class CustomRequestMappingHandlerAdapter {
private int handlerAdapters = 0;
@Bean @Bean
WebMvcRegistrations webMvcRegistrationsHandlerAdapter() { WebMvcRegistrations webMvcRegistrationsHandlerAdapter() {
return new WebMvcRegistrations() { return new WebMvcRegistrations() {
@Override @Override
public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() { public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() {
CustomRequestMappingHandlerAdapter.this.handlerAdapters++;
return new MyRequestMappingHandlerAdapter(); return new MyRequestMappingHandlerAdapter();
} }
@ -1124,6 +1143,30 @@ class WebMvcAutoConfigurationTests {
} }
@Configuration(proxyBeanMethods = false)
static class CustomExceptionHandlerExceptionResolver {
private int exceptionResolvers = 0;
@Bean
WebMvcRegistrations webMvcRegistrationsHandlerAdapter() {
return new WebMvcRegistrations() {
@Override
public ExceptionHandlerExceptionResolver getExceptionHandlerExceptionResolver() {
CustomExceptionHandlerExceptionResolver.this.exceptionResolvers++;
return new MyExceptionHandlerExceptionResolver();
}
};
}
}
static class MyExceptionHandlerExceptionResolver extends ExceptionHandlerExceptionResolver {
}
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@Import({ CustomRequestMappingHandlerMapping.class, CustomRequestMappingHandlerAdapter.class }) @Import({ CustomRequestMappingHandlerMapping.class, CustomRequestMappingHandlerAdapter.class })
static class MultipleWebMvcRegistrations { static class MultipleWebMvcRegistrations {

Loading…
Cancel
Save