diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java index e0a10efa7f8..fdc950ef8d0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java @@ -63,8 +63,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertEquals; @@ -243,6 +245,16 @@ public class EndpointWebMvcAutoConfigurationTests { assertAllClosed(); } + @Test + public void singleRequestMappingInfoHandlerMappingBean() throws Exception { + this.applicationContext.register(RootConfig.class, BaseConfiguration.class, + ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); + this.applicationContext.refresh(); + RequestMappingInfoHandlerMapping mapping = this.applicationContext + .getBean(RequestMappingInfoHandlerMapping.class); + assertThat(mapping, not(instanceOf(EndpointHandlerMapping.class))); + } + private void assertAllClosed() throws Exception { assertContent("/controller", ports.get().server, null); assertContent("/endpoint", ports.get().server, null); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java index 71734fc0151..d91527072f5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java @@ -43,6 +43,7 @@ import org.springframework.context.ResourceLoaderAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.Primary; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.core.convert.converter.Converter; @@ -73,6 +74,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.servlet.i18n.FixedLocaleResolver; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; import org.springframework.web.servlet.view.BeanNameViewResolver; import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; @@ -326,8 +328,7 @@ public class WebMvcAutoConfiguration { } /** - * Configuration equivalent to {@code @EnableWebMvc} but with extra - * {@link WebMvcProperties} support. + * Configuration equivalent to {@code @EnableWebMvc}. */ @Configuration public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration { @@ -344,5 +345,14 @@ public class WebMvcAutoConfiguration { return adapter; } + @Bean + @Primary + @Override + public RequestMappingHandlerMapping requestMappingHandlerMapping() { + // Must be @Primary for MvcUriComponentsBuilder to work + return super.requestMappingHandlerMapping(); + } + } + }