diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
index 464b748c161..f5d3e212bcf 100644
--- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
+++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
@@ -820,7 +820,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
* Comparator capable of sorting {@link RequestMappingInfo}s (RHIs) so that sorting a list with this comparator will
* result in:
- RHIs with {@linkplain RequestMappingInfo#matchedPaths better matched paths} take prescedence
* over those with a weaker match (as expressed by the {@linkplain PathMatcher#getPatternComparator(String) path
- * pattern comparator}.) Typically, this means that patterns without wild chards and uri templates will be ordered
+ * pattern comparator}.) Typically, this means that patterns without wild cards and uri templates will be ordered
* before those without.
- RHIs with one single {@linkplain RequestMappingInfo#methods request method} will be
* ordered before those without a method, or with more than one method.
- RHIs with more {@linkplain
* RequestMappingInfo#params request parameters} will be ordered before those with less parameters
@@ -838,6 +838,16 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
if (pathComparison != 0) {
return pathComparison;
}
+ int info1ParamCount = info1.params.length;
+ int info2ParamCount = info2.params.length;
+ if (info1ParamCount != info2ParamCount) {
+ return info2ParamCount - info1ParamCount;
+ }
+ int info1HeaderCount = info1.headers.length;
+ int info2HeaderCount = info2.headers.length;
+ if (info1HeaderCount != info2HeaderCount) {
+ return info2HeaderCount - info1HeaderCount;
+ }
int info1MethodCount = info1.methods.length;
int info2MethodCount = info2.methods.length;
if (info1MethodCount == 0 && info2MethodCount > 0) {
@@ -852,16 +862,6 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
else if (info2MethodCount == 1 & info1MethodCount > 1) {
return 1;
}
- int info1ParamCount = info1.params.length;
- int info2ParamCount = info2.params.length;
- if (info1ParamCount != info2ParamCount) {
- return info2ParamCount - info1ParamCount;
- }
- int info1HeaderCount = info1.headers.length;
- int info2HeaderCount = info2.headers.length;
- if (info1HeaderCount != info2HeaderCount) {
- return info2HeaderCount - info1HeaderCount;
- }
return 0;
}
}
diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java
index b60553f9c11..2be7a3ac4c1 100644
--- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java
+++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java
@@ -974,6 +974,22 @@ public class ServletAnnotationControllerTests {
}
+ @Test
+ public void ambiguousParams() throws ServletException, IOException {
+ initServlet(AmbiguousParamsController.class);
+
+ MockHttpServletRequest request;// = new MockHttpServletRequest("GET", "/test");
+ MockHttpServletResponse response;// = new MockHttpServletResponse();
+// servlet.service(request, response);
+// assertEquals("noParams", response.getContentAsString());
+
+ request = new MockHttpServletRequest("GET", "/test");
+ request.addParameter("myParam", "42");
+ response = new MockHttpServletResponse();
+ servlet.service(request, response);
+ assertEquals("myParam-42", response.getContentAsString());
+ }
+
/*
* Controllers
@@ -1647,6 +1663,21 @@ public class ServletAnnotationControllerTests {
}
}
+ @Controller
+ @RequestMapping("/test*")
+ private static class AmbiguousParamsController {
+
+ @RequestMapping(method = RequestMethod.GET)
+ public void noParams(Writer writer) throws IOException {
+ writer.write("noParams");
+ }
+
+ @RequestMapping(params = "myParam")
+ public void param(@RequestParam("myParam") int myParam, Writer writer) throws IOException {
+ writer.write("myParam-" + myParam);
+ }
+
+ }
}