Browse Source

HandlerMethod pre-resolves parameter types at construction time

Issue: SPR-15186
pull/1304/head
Juergen Hoeller 8 years ago
parent
commit
8038fb9c8b
  1. 14
      spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java
  2. 2
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java
  3. 1
      spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java
  4. 14
      spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java
  5. 2
      spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java

14
spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.SynthesizingMethodParameter;
@ -36,9 +37,10 @@ import org.springframework.util.ClassUtils; @@ -36,9 +37,10 @@ import org.springframework.util.ClassUtils;
* Provides convenient access to method parameters, the method return value,
* method annotations, etc.
*
* <p>The class may be created with a bean instance or with a bean name (e.g. lazy-init bean,
* prototype bean). Use {@link #createWithResolvedBean()} to obtain a {@code HandlerMethod}
* instance with a bean instance resolved through the associated {@link BeanFactory}.
* <p>The class may be created with a bean instance or with a bean name
* (e.g. lazy-init bean, prototype bean). Use {@link #createWithResolvedBean()}
* to obtain a {@code HandlerMethod} instance with a bean instance resolved
* through the associated {@link BeanFactory}.
*
* @author Arjen Poutsma
* @author Rossen Stoyanchev
@ -148,7 +150,9 @@ public class HandlerMethod { @@ -148,7 +150,9 @@ public class HandlerMethod {
int count = this.bridgedMethod.getParameterCount();
MethodParameter[] result = new MethodParameter[count];
for (int i = 0; i < count; i++) {
result[i] = new HandlerMethodParameter(i);
HandlerMethodParameter parameter = new HandlerMethodParameter(i);
GenericTypeResolver.resolveParameterType(parameter, this.beanType);
result[i] = parameter;
}
return result;
}

2
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java

@ -22,7 +22,6 @@ import java.lang.reflect.Type; @@ -22,7 +22,6 @@ import java.lang.reflect.Type;
import java.util.Arrays;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.ResolvableType;
@ -127,7 +126,6 @@ public class InvocableHandlerMethod extends HandlerMethod { @@ -127,7 +126,6 @@ public class InvocableHandlerMethod extends HandlerMethod {
for (int i = 0; i < parameters.length; i++) {
MethodParameter parameter = parameters[i];
parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);
GenericTypeResolver.resolveParameterType(parameter, getBean().getClass());
args[i] = resolveProvidedArgument(parameter, providedArgs);
if (args[i] != null) {
continue;

1
spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java

@ -123,7 +123,6 @@ public class InvocableHandlerMethod extends HandlerMethod { @@ -123,7 +123,6 @@ public class InvocableHandlerMethod extends HandlerMethod {
List<Mono<Object>> argMonos = Stream.of(getMethodParameters())
.map(param -> {
param.initParameterNameDiscovery(this.parameterNameDiscoverer);
GenericTypeResolver.resolveParameterType(param, getBean().getClass());
return findProvidedArgument(param, providedArgs)
.map(Mono::just)
.orElseGet(() -> {

14
spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.SynthesizingMethodParameter;
@ -36,9 +37,10 @@ import org.springframework.util.ClassUtils; @@ -36,9 +37,10 @@ import org.springframework.util.ClassUtils;
* Provides convenient access to method parameters, the method return value,
* method annotations, etc.
*
* <p>The class may be created with a bean instance or with a bean name (e.g. lazy-init bean,
* prototype bean). Use {@link #createWithResolvedBean()} to obtain a {@code HandlerMethod}
* instance with a bean instance resolved through the associated {@link BeanFactory}.
* <p>The class may be created with a bean instance or with a bean name
* (e.g. lazy-init bean, prototype bean). Use {@link #createWithResolvedBean()}
* to obtain a {@code HandlerMethod} instance with a bean instance resolved
* through the associated {@link BeanFactory}.
*
* @author Arjen Poutsma
* @author Rossen Stoyanchev
@ -149,7 +151,9 @@ public class HandlerMethod { @@ -149,7 +151,9 @@ public class HandlerMethod {
int count = this.bridgedMethod.getParameterCount();
MethodParameter[] result = new MethodParameter[count];
for (int i = 0; i < count; i++) {
result[i] = new HandlerMethodParameter(i);
HandlerMethodParameter parameter = new HandlerMethodParameter(i);
GenericTypeResolver.resolveParameterType(parameter, this.beanType);
result[i] = parameter;
}
return result;
}

2
spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java

@ -21,7 +21,6 @@ import java.lang.reflect.Method; @@ -21,7 +21,6 @@ import java.lang.reflect.Method;
import java.util.Arrays;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.util.ClassUtils;
@ -150,7 +149,6 @@ public class InvocableHandlerMethod extends HandlerMethod { @@ -150,7 +149,6 @@ public class InvocableHandlerMethod extends HandlerMethod {
for (int i = 0; i < parameters.length; i++) {
MethodParameter parameter = parameters[i];
parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);
GenericTypeResolver.resolveParameterType(parameter, getBean().getClass());
args[i] = resolveProvidedArgument(parameter, providedArgs);
if (args[i] != null) {
continue;

Loading…
Cancel
Save