From 8740c2dc18482747c9e6d489718c08967f1e3f7c Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 13 Jan 2020 21:32:39 +0000 Subject: [PATCH] Warning against split URL handling in docs Closes gh-24304 --- .../servlet/config/annotation/ViewControllerRegistry.java | 6 +++++- src/docs/asciidoc/web/webmvc.adoc | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistry.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistry.java index cf940cca2a..a367eed58c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistry.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,6 +61,10 @@ public class ViewControllerRegistry { *

Patterns like {@code "/admin/**"} or {@code "/articles/{articlename:\\w+}"} * are allowed. See {@link org.springframework.util.AntPathMatcher} for more details on the * syntax. + *

Note: If an {@code @RequestMapping} method is mapped + * to a URL for any HTTP method then a view controller cannot handle the + * same URL. For this reason it is recommended to avoid splitting URL + * handling across an annotated controller and a view controller. */ public ViewControllerRegistration addViewController(String urlPath) { ViewControllerRegistration registration = new ViewControllerRegistration(urlPath); diff --git a/src/docs/asciidoc/web/webmvc.adoc b/src/docs/asciidoc/web/webmvc.adoc index c993a6de3f..6de7b41083 100644 --- a/src/docs/asciidoc/web/webmvc.adoc +++ b/src/docs/asciidoc/web/webmvc.adoc @@ -5399,6 +5399,13 @@ using the `` element: ---- +If an `@RequestMapping` method is mapped to a URL for any HTTP method then a view +controller cannot be used to handle the same URL. This is because a match by URL to an +annotated controller is considered a strong enough indication of endpoint ownership so +that a 405 (METHOD_NOT_ALLOWED), a 415 (UNSUPPORTED_MEDIA_TYPE), or similar response can +be sent to the client to help with debugging. For this reason it is recommended to avoid +splitting URL handling across an annotated controller and a view controller. + [[mvc-config-view-resolvers]]