Polishing

This commit is contained in:
Juergen Hoeller
2018-08-09 00:49:54 +02:00
parent 688ef9ad46
commit f3184a0878
13 changed files with 164 additions and 154 deletions

View File

@@ -114,6 +114,20 @@ import org.springframework.web.util.WebUtils;
public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
implements BeanFactoryAware, InitializingBean {
/**
* MethodFilter that matches {@link InitBinder @InitBinder} methods.
*/
public static final MethodFilter INIT_BINDER_METHODS = method ->
(AnnotationUtils.findAnnotation(method, InitBinder.class) != null);
/**
* MethodFilter that matches {@link ModelAttribute @ModelAttribute} methods.
*/
public static final MethodFilter MODEL_ATTRIBUTE_METHODS = method ->
((AnnotationUtils.findAnnotation(method, RequestMapping.class) == null) &&
(AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null));
@Nullable
private List<HandlerMethodArgumentResolver> customArgumentResolvers;
@@ -1002,18 +1016,4 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
return mav;
}
/**
* MethodFilter that matches {@link InitBinder @InitBinder} methods.
*/
public static final MethodFilter INIT_BINDER_METHODS = method ->
AnnotationUtils.findAnnotation(method, InitBinder.class) != null;
/**
* MethodFilter that matches {@link ModelAttribute @ModelAttribute} methods.
*/
public static final MethodFilter MODEL_ATTRIBUTE_METHODS = method ->
((AnnotationUtils.findAnnotation(method, RequestMapping.class) == null) &&
(AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 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.
@@ -66,31 +66,29 @@ public class HandlerMethodAnnotationDetectionTests {
@Parameters(name = "controller [{0}], auto-proxy [{1}]")
public static Object[][] handlerTypes() {
return new Object[][] {
{ SimpleController.class, true }, // CGLIB proxy
{ SimpleController.class, false },
{ SimpleController.class, true }, // CGLib proxy
{ SimpleController.class, false },
{ AbstractClassController.class, true }, // CGLIB proxy
{ AbstractClassController.class, false },
{ AbstractClassController.class, true }, // CGLib proxy
{ AbstractClassController.class, false },
{ ParameterizedAbstractClassController.class, true }, // CGLIB proxy
{ ParameterizedAbstractClassController.class, false },
{ ParameterizedAbstractClassController.class, true }, // CGLib proxy
{ ParameterizedAbstractClassController.class, false },
{ ParameterizedSubclassOverridesDefaultMappings.class, true }, // CGLIB proxy
{ ParameterizedSubclassOverridesDefaultMappings.class, false },
{ ParameterizedSubclassOverridesDefaultMappings.class, true }, // CGLib proxy
{ ParameterizedSubclassOverridesDefaultMappings.class, false },
// TODO [SPR-9517] Enable ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass test cases
// { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, true }, // CGLIB proxy
// { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, false },
// TODO [SPR-9517] Enable ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass test cases
// { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, true }, // CGLib proxy
// { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, false },
{ InterfaceController.class, true }, // JDK dynamic proxy
{ InterfaceController.class, false },
{ InterfaceController.class, true }, // JDK dynamic proxy
{ InterfaceController.class, false },
{ ParameterizedInterfaceController.class, false }, // no AOP
{ SupportClassController.class, true }, // CGLib proxy
{ SupportClassController.class, false }
{ ParameterizedInterfaceController.class, false }, // no AOP
{ SupportClassController.class, true }, // CGLIB proxy
{ SupportClassController.class, false }
};
}
@@ -100,7 +98,8 @@ public class HandlerMethodAnnotationDetectionTests {
private ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver();
public HandlerMethodAnnotationDetectionTests(final Class<?> controllerType, boolean useAutoProxy) {
public HandlerMethodAnnotationDetectionTests(Class<?> controllerType, boolean useAutoProxy) {
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.registerBeanDefinition("controller", new RootBeanDefinition(controllerType));
context.registerBeanDefinition("handlerMapping", new RootBeanDefinition(RequestMappingHandlerMapping.class));
@@ -120,12 +119,6 @@ public class HandlerMethodAnnotationDetectionTests {
context.close();
}
class TestPointcut extends StaticMethodMatcherPointcut {
@Override
public boolean matches(Method method, @Nullable Class<?> clazz) {
return method.getName().equals("hashCode");
}
}
@Test
public void testRequestMappingMethod() throws Exception {
@@ -203,9 +196,9 @@ public class HandlerMethodAnnotationDetectionTests {
public abstract String handleException(Exception exception);
}
/**
* CONTROLLER WITH ABSTRACT CLASS
*
* <p>All annotations can be on methods in the abstract class except parameter annotations.
*/
static class AbstractClassController extends MappingAbstractClass {
@@ -232,10 +225,10 @@ public class HandlerMethodAnnotationDetectionTests {
}
}
// SPR-9374
// SPR-9374
@RequestMapping
static interface MappingInterface {
interface MappingInterface {
@InitBinder
void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String thePattern);
@@ -252,14 +245,11 @@ public class HandlerMethodAnnotationDetectionTests {
String handleException(Exception exception);
}
/**
* CONTROLLER WITH INTERFACE
*
* JDK Dynamic proxy:
* All annotations must be on the interface.
*
* Without AOP:
* Annotations can be on interface methods except parameter annotations.
* <p>JDK Dynamic proxy: All annotations must be on the interface.
* <p>Without AOP: Annotations can be on interface methods except parameter annotations.
*/
static class InterfaceController implements MappingInterface {
@@ -304,9 +294,9 @@ public class HandlerMethodAnnotationDetectionTests {
public abstract String handleException(Exception exception);
}
/**
* CONTROLLER WITH PARAMETERIZED BASE CLASS
*
* <p>All annotations can be on methods in the abstract class except parameter annotations.
*/
static class ParameterizedAbstractClassController extends MappingGenericAbstractClass<String, Date, Date> {
@@ -333,6 +323,7 @@ public class HandlerMethodAnnotationDetectionTests {
}
}
@Controller
static abstract class MappedGenericAbstractClassWithConcreteImplementations<A, B, C> {
@@ -353,6 +344,7 @@ public class HandlerMethodAnnotationDetectionTests {
public abstract String handleException(Exception exception);
}
static class ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass extends
MappedGenericAbstractClassWithConcreteImplementations<String, Date, Date> {
@@ -375,6 +367,7 @@ public class HandlerMethodAnnotationDetectionTests {
}
}
@Controller
static abstract class GenericAbstractClassDeclaresDefaultMappings<A, B, C> {
@@ -395,6 +388,7 @@ public class HandlerMethodAnnotationDetectionTests {
public abstract String handleException(Exception exception);
}
static class ParameterizedSubclassOverridesDefaultMappings
extends GenericAbstractClassDeclaresDefaultMappings<String, Date, Date> {
@@ -425,8 +419,9 @@ public class HandlerMethodAnnotationDetectionTests {
}
}
@RequestMapping
static interface MappingGenericInterface<A, B, C> {
interface MappingGenericInterface<A, B, C> {
@InitBinder
void initBinder(WebDataBinder dataBinder, A thePattern);
@@ -443,11 +438,10 @@ public class HandlerMethodAnnotationDetectionTests {
String handleException(Exception exception);
}
/**
* CONTROLLER WITH PARAMETERIZED INTERFACE
*
* <p>All annotations can be on interface except parameter annotations.
*
* <p>Cannot be used as JDK dynamic proxy since parameterized interface does not contain type information.
*/
static class ParameterizedInterfaceController implements MappingGenericInterface<String, Date, Date> {
@@ -483,7 +477,6 @@ public class HandlerMethodAnnotationDetectionTests {
/**
* SPR-8248
*
* <p>Support class contains all annotations. Subclass has type-level @{@link RequestMapping}.
*/
@Controller