Skip to content

Commit a98a618

Browse files
committed
HandlerMethod pre-resolves parameter types at construction time
Issue: SPR-15186 (cherry picked from commit 8038fb9)
1 parent 3304efd commit a98a618

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -24,6 +24,7 @@
2424

2525
import org.springframework.beans.factory.BeanFactory;
2626
import org.springframework.core.BridgeMethodResolver;
27+
import org.springframework.core.GenericTypeResolver;
2728
import org.springframework.core.MethodParameter;
2829
import org.springframework.core.annotation.AnnotatedElementUtils;
2930
import org.springframework.core.annotation.SynthesizingMethodParameter;
@@ -36,9 +37,10 @@
3637
* Provides convenient access to method parameters, the method return value,
3738
* method annotations, etc.
3839
*
39-
* <p>The class may be created with a bean instance or with a bean name (e.g. lazy-init bean,
40-
* prototype bean). Use {@link #createWithResolvedBean()} to obtain a {@code HandlerMethod}
41-
* instance with a bean instance resolved through the associated {@link BeanFactory}.
40+
* <p>The class may be created with a bean instance or with a bean name
41+
* (e.g. lazy-init bean, prototype bean). Use {@link #createWithResolvedBean()}
42+
* to obtain a {@code HandlerMethod} instance with a bean instance resolved
43+
* through the associated {@link BeanFactory}.
4244
*
4345
* @author Arjen Poutsma
4446
* @author Rossen Stoyanchev
@@ -148,7 +150,9 @@ private MethodParameter[] initMethodParameters() {
148150
int count = this.bridgedMethod.getParameterTypes().length;
149151
MethodParameter[] result = new MethodParameter[count];
150152
for (int i = 0; i < count; i++) {
151-
result[i] = new HandlerMethodParameter(i);
153+
HandlerMethodParameter parameter = new HandlerMethodParameter(i);
154+
GenericTypeResolver.resolveParameterType(parameter, this.beanType);
155+
result[i] = parameter;
152156
}
153157
return result;
154158
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Arrays;
2323

2424
import org.springframework.core.DefaultParameterNameDiscoverer;
25-
import org.springframework.core.GenericTypeResolver;
2625
import org.springframework.core.MethodParameter;
2726
import org.springframework.core.ParameterNameDiscoverer;
2827
import org.springframework.core.ResolvableType;
@@ -127,7 +126,6 @@ private Object[] getMethodArgumentValues(Message<?> message, Object... providedA
127126
for (int i = 0; i < parameters.length; i++) {
128127
MethodParameter parameter = parameters[i];
129128
parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);
130-
GenericTypeResolver.resolveParameterType(parameter, getBean().getClass());
131129
args[i] = resolveProvidedArgument(parameter, providedArgs);
132130
if (args[i] != null) {
133131
continue;

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -24,6 +24,7 @@
2424

2525
import org.springframework.beans.factory.BeanFactory;
2626
import org.springframework.core.BridgeMethodResolver;
27+
import org.springframework.core.GenericTypeResolver;
2728
import org.springframework.core.MethodParameter;
2829
import org.springframework.core.annotation.AnnotatedElementUtils;
2930
import org.springframework.core.annotation.SynthesizingMethodParameter;
@@ -36,9 +37,10 @@
3637
* Provides convenient access to method parameters, the method return value,
3738
* method annotations, etc.
3839
*
39-
* <p>The class may be created with a bean instance or with a bean name (e.g. lazy-init bean,
40-
* prototype bean). Use {@link #createWithResolvedBean()} to obtain a {@code HandlerMethod}
41-
* instance with a bean instance resolved through the associated {@link BeanFactory}.
40+
* <p>The class may be created with a bean instance or with a bean name
41+
* (e.g. lazy-init bean, prototype bean). Use {@link #createWithResolvedBean()}
42+
* to obtain a {@code HandlerMethod} instance with a bean instance resolved
43+
* through the associated {@link BeanFactory}.
4244
*
4345
* @author Arjen Poutsma
4446
* @author Rossen Stoyanchev
@@ -149,7 +151,9 @@ private MethodParameter[] initMethodParameters() {
149151
int count = this.bridgedMethod.getParameterTypes().length;
150152
MethodParameter[] result = new MethodParameter[count];
151153
for (int i = 0; i < count; i++) {
152-
result[i] = new HandlerMethodParameter(i);
154+
HandlerMethodParameter parameter = new HandlerMethodParameter(i);
155+
GenericTypeResolver.resolveParameterType(parameter, this.beanType);
156+
result[i] = parameter;
153157
}
154158
return result;
155159
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Arrays;
2222

2323
import org.springframework.core.DefaultParameterNameDiscoverer;
24-
import org.springframework.core.GenericTypeResolver;
2524
import org.springframework.core.MethodParameter;
2625
import org.springframework.core.ParameterNameDiscoverer;
2726
import org.springframework.util.ClassUtils;
@@ -150,7 +149,6 @@ private Object[] getMethodArgumentValues(NativeWebRequest request, ModelAndViewC
150149
for (int i = 0; i < parameters.length; i++) {
151150
MethodParameter parameter = parameters[i];
152151
parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);
153-
GenericTypeResolver.resolveParameterType(parameter, getBean().getClass());
154152
args[i] = resolveProvidedArgument(parameter, providedArgs);
155153
if (args[i] != null) {
156154
continue;

0 commit comments

Comments
 (0)