Remove warning about empty @RequestMapping path

See gh-22543
This commit is contained in:
Rossen Stoyanchev
2019-04-09 13:12:35 -04:00
parent 5b17bb2e14
commit f839c1f9cd
8 changed files with 15 additions and 66 deletions

View File

@@ -43,7 +43,6 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsUtils;
import org.springframework.web.method.HandlerMethod;
@@ -616,15 +615,6 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
}
private void validateMethodMapping(HandlerMethod handlerMethod, T mapping) {
// Log a warning if the supplied mapping maps the supplied HandlerMethod
// only to empty paths.
if (logger.isWarnEnabled() && getMappingPathPatterns(mapping).stream().noneMatch(StringUtils::hasText)) {
logger.warn(String.format(
"Handler method '%s' in bean '%s' is not mapped to an explicit path. " +
"If you wish to map to all paths, please map explicitly to \"/**\" or \"**\".",
handlerMethod, handlerMethod.getBean()));
}
// Assert that the supplied mapping is unique.
HandlerMethod existingHandlerMethod = this.mappingLookup.get(mapping);
if (existingHandlerMethod != null && !existingHandlerMethod.equals(handlerMethod)) {

View File

@@ -78,7 +78,7 @@ public class RequestMappingInfoHandlerMappingTests {
private HandlerMethod barMethod;
private HandlerMethod rootMethod;
private HandlerMethod emptyMethod;
@Before
@@ -88,7 +88,7 @@ public class RequestMappingInfoHandlerMappingTests {
this.fooMethod = new HandlerMethod(testController, "foo");
this.fooParamMethod = new HandlerMethod(testController, "fooParam");
this.barMethod = new HandlerMethod(testController, "bar");
this.rootMethod = new HandlerMethod(testController, "root");
this.emptyMethod = new HandlerMethod(testController, "empty");
this.handlerMapping = new TestRequestMappingInfoHandlerMapping();
this.handlerMapping.registerHandler(testController);
@@ -125,12 +125,12 @@ public class RequestMappingInfoHandlerMappingTests {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
HandlerMethod handlerMethod = getHandler(request);
assertEquals(this.rootMethod.getMethod(), handlerMethod.getMethod());
assertEquals(this.emptyMethod.getMethod(), handlerMethod.getMethod());
request = new MockHttpServletRequest("GET", "/");
handlerMethod = getHandler(request);
assertEquals(this.rootMethod.getMethod(), handlerMethod.getMethod());
assertEquals(this.emptyMethod.getMethod(), handlerMethod.getMethod());
}
@Test
@@ -465,8 +465,8 @@ public class RequestMappingInfoHandlerMappingTests {
public void bar() {
}
@RequestMapping("/")
public void root() {
@RequestMapping("")
public void empty() {
}
@RequestMapping(value = "/person/{id}", method = RequestMethod.PUT, consumes="application/xml")

View File

@@ -228,7 +228,7 @@ public class RequestMappingHandlerMappingTests {
@RequestMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
static class ComposedAnnotationController {
@RequestMapping("/**")
@RequestMapping
public void handle() {
}

View File

@@ -2016,7 +2016,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
@Controller
static class ControllerWithEmptyValueMapping {
@RequestMapping("/**")
@RequestMapping("")
public void myPath2(HttpServletResponse response) throws IOException {
throw new IllegalStateException("test");
}
@@ -2035,7 +2035,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
@Controller
private static class ControllerWithErrorThrown {
@RequestMapping("/**")
@RequestMapping("")
public void myPath2(HttpServletResponse response) throws IOException {
throw new AssertionError("test");
}
@@ -3629,7 +3629,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
@Controller
static class HttpHeadersResponseController {
@RequestMapping(value = "/*", method = RequestMethod.POST)
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public HttpHeaders create() throws URISyntaxException {
HttpHeaders headers = new HttpHeaders();