Browse Source

Discover controllers based on type @RequestMapping

This was supported in DefaultAnnotationHandlerMapping but not in the
RequestMappingHandlerMapping. The specific scenario where this matters
is a controller decorated with a JDK proxy. In this scenario the
HandlerMapping looks at interfaces only to decide if the bean is a
controller. The @Controller annotation is better left (and required)
on the class.

Issue: SPR-9374
Backport-Issue: SPR-9384
Backport-Commit: f61f4a960e
3.1.x
Rossen Stoyanchev 14 years ago
parent
commit
2fa0e63e5a
  1. 7
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java
  2. 6
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java

7
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 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.
@ -83,7 +83,8 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi @@ -83,7 +83,8 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
*/
@Override
protected boolean isHandler(Class<?> beanType) {
return AnnotationUtils.findAnnotation(beanType, Controller.class) != null;
return ((AnnotationUtils.findAnnotation(beanType, Controller.class) != null) ||
(AnnotationUtils.findAnnotation(beanType, RequestMapping.class) != null));
}
/**
@ -129,7 +130,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi @@ -129,7 +130,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
* The custom {@link RequestCondition} can be of any type so long as the
* same condition type is returned from all calls to this method in order
* to ensure custom request conditions can be combined and compared.
* @param method the handler method for which to create the condition
* @param handlerType the handler type for which to create the condition
* @return the condition, or {@code null}
*/
protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType) {

6
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java

@ -208,8 +208,9 @@ public class HandlerMethodAnnotationDetectionTests { @@ -208,8 +208,9 @@ public class HandlerMethodAnnotationDetectionTests {
}
}
// SPR-9374
@Controller
@RequestMapping
static interface MappingInterface {
@InitBinder
@ -300,8 +301,7 @@ public class HandlerMethodAnnotationDetectionTests { @@ -300,8 +301,7 @@ public class HandlerMethodAnnotationDetectionTests {
}
}
@Controller
@RequestMapping
static interface MappingParameterizedInterface<A, B, C> {
@InitBinder

Loading…
Cancel
Save