Skip to content

Commit 8740c2d

Browse files
committed
Warning against split URL handling in docs
Closes gh-24304
1 parent 5debd86 commit 8740c2d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistry.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,6 +61,10 @@ public ViewControllerRegistry(@Nullable ApplicationContext applicationContext) {
6161
* <p>Patterns like {@code "/admin/**"} or {@code "/articles/{articlename:\\w+}"}
6262
* are allowed. See {@link org.springframework.util.AntPathMatcher} for more details on the
6363
* syntax.
64+
* <p><strong>Note:</strong> If an {@code @RequestMapping} method is mapped
65+
* to a URL for any HTTP method then a view controller cannot handle the
66+
* same URL. For this reason it is recommended to avoid splitting URL
67+
* handling across an annotated controller and a view controller.
6468
*/
6569
public ViewControllerRegistration addViewController(String urlPath) {
6670
ViewControllerRegistration registration = new ViewControllerRegistration(urlPath);

src/docs/asciidoc/web/webmvc.adoc

+7
Original file line numberDiff line numberDiff line change
@@ -5399,6 +5399,13 @@ using the `<mvc:view-controller>` element:
53995399
<mvc:view-controller path="/" view-name="home"/>
54005400
----
54015401

5402+
If an `@RequestMapping` method is mapped to a URL for any HTTP method then a view
5403+
controller cannot be used to handle the same URL. This is because a match by URL to an
5404+
annotated controller is considered a strong enough indication of endpoint ownership so
5405+
that a 405 (METHOD_NOT_ALLOWED), a 415 (UNSUPPORTED_MEDIA_TYPE), or similar response can
5406+
be sent to the client to help with debugging. For this reason it is recommended to avoid
5407+
splitting URL handling across an annotated controller and a view controller.
5408+
54025409

54035410

54045411
[[mvc-config-view-resolvers]]

0 commit comments

Comments
 (0)