@@ -54,7 +54,7 @@ public class HandlerMethod {
54
54
55
55
private final BeanFactory beanFactory ;
56
56
57
- private MethodParameter [] parameters ;
57
+ private final MethodParameter [] parameters ;
58
58
59
59
private final Method bridgedMethod ;
60
60
@@ -69,6 +69,16 @@ public HandlerMethod(Object bean, Method method) {
69
69
this .beanFactory = null ;
70
70
this .method = method ;
71
71
this .bridgedMethod = BridgeMethodResolver .findBridgedMethod (method );
72
+ this .parameters = initMethodParameters ();
73
+ }
74
+
75
+ private MethodParameter [] initMethodParameters () {
76
+ int count = this .bridgedMethod .getParameterTypes ().length ;
77
+ MethodParameter [] result = new MethodParameter [count ];
78
+ for (int i = 0 ; i < count ; i ++) {
79
+ result [i ] = new HandlerMethodParameter (i );
80
+ }
81
+ return result ;
72
82
}
73
83
74
84
/**
@@ -82,6 +92,7 @@ public HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes)
82
92
this .beanFactory = null ;
83
93
this .method = bean .getClass ().getMethod (methodName , parameterTypes );
84
94
this .bridgedMethod = BridgeMethodResolver .findBridgedMethod (method );
95
+ this .parameters = initMethodParameters ();
85
96
}
86
97
87
98
/**
@@ -99,10 +110,11 @@ public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) {
99
110
this .beanFactory = beanFactory ;
100
111
this .method = method ;
101
112
this .bridgedMethod = BridgeMethodResolver .findBridgedMethod (method );
113
+ this .parameters = initMethodParameters ();
102
114
}
103
115
104
116
/**
105
- * Create an instance from another {@code HandlerMethod} .
117
+ * Copy constructor for use in sub-classes .
106
118
*/
107
119
protected HandlerMethod (HandlerMethod handlerMethod ) {
108
120
Assert .notNull (handlerMethod , "HandlerMethod is required" );
@@ -113,6 +125,19 @@ protected HandlerMethod(HandlerMethod handlerMethod) {
113
125
this .parameters = handlerMethod .parameters ;
114
126
}
115
127
128
+ /**
129
+ * Re-create HandlerMethod with the resolved handler.
130
+ */
131
+ private HandlerMethod (HandlerMethod handlerMethod , Object handler ) {
132
+ Assert .notNull (handlerMethod , "handlerMethod is required" );
133
+ Assert .notNull (handler , "handler is required" );
134
+ this .bean = handler ;
135
+ this .beanFactory = handlerMethod .beanFactory ;
136
+ this .method = handlerMethod .method ;
137
+ this .bridgedMethod = handlerMethod .bridgedMethod ;
138
+ this .parameters = handlerMethod .parameters ;
139
+ }
140
+
116
141
/**
117
142
* Returns the bean for this handler method.
118
143
*/
@@ -150,13 +175,6 @@ protected Method getBridgedMethod() {
150
175
* Returns the method parameters for this handler method.
151
176
*/
152
177
public MethodParameter [] getMethodParameters () {
153
- if (this .parameters == null ) {
154
- int parameterCount = this .bridgedMethod .getParameterTypes ().length ;
155
- this .parameters = new MethodParameter [parameterCount ];
156
- for (int i = 0 ; i < parameterCount ; i ++) {
157
- this .parameters [i ] = new HandlerMethodParameter (i );
158
- }
159
- }
160
178
return this .parameters ;
161
179
}
162
180
@@ -201,9 +219,7 @@ public HandlerMethod createWithResolvedBean() {
201
219
String beanName = (String ) this .bean ;
202
220
handler = this .beanFactory .getBean (beanName );
203
221
}
204
- HandlerMethod handlerMethod = new HandlerMethod (handler , this .method );
205
- handlerMethod .parameters = getMethodParameters ();
206
- return handlerMethod ;
222
+ return new HandlerMethod (this , handler );
207
223
}
208
224
209
225
@ Override
0 commit comments