Make RequestMappingHandlerMapping @Primary
Update WebMvcAutoConfiguration so that the RequestMappingHandlerMapping bean is @Primary. Prior to this commit a NoUniqueBeanDefinitionException would be thrown then using the MvcUriComponentsBuilder. Fixes gh-2237
This commit is contained in:
@@ -25,6 +25,7 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
|
||||
@@ -54,8 +55,10 @@ import org.springframework.util.SocketUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
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.assertFalse;
|
||||
@@ -229,6 +232,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);
|
||||
|
||||
Reference in New Issue
Block a user