42
42
import org .springframework .core .MethodParameter ;
43
43
import org .springframework .core .ParameterNameDiscoverer ;
44
44
import org .springframework .core .annotation .AnnotatedElementUtils ;
45
- import org .springframework .core .annotation .SynthesizingMethodParameter ;
45
+ import org .springframework .core .annotation .AnnotatedMethod ;
46
46
import org .springframework .lang .Nullable ;
47
47
import org .springframework .objenesis .ObjenesisException ;
48
48
import org .springframework .objenesis .SpringObjenesis ;
@@ -538,22 +538,23 @@ public UriComponentsBuilder withMethod(Class<?> controllerType, Method method, O
538
538
private static UriComponentsBuilder fromMethodInternal (@ Nullable UriComponentsBuilder builder ,
539
539
Class <?> controllerType , Method method , Object ... args ) {
540
540
541
+ AnnotatedMethod annotatedMethod = new AnnotatedMethod (method );
541
542
builder = getBaseUrlToUse (builder );
542
543
543
544
// Externally configured prefix via PathConfigurer..
544
545
String prefix = getPathPrefix (controllerType );
545
546
builder .path (prefix );
546
547
547
548
String typePath = getClassMapping (controllerType );
548
- String methodPath = getMethodMapping (method );
549
+ String methodPath = getMethodMapping (annotatedMethod );
549
550
String path = pathMatcher .combine (typePath , methodPath );
550
551
path = PathPatternParser .defaultInstance .initFullPathPattern (path );
551
552
if (!StringUtils .hasText (prefix + path )) {
552
553
path = "/" ;
553
554
}
554
555
builder .path (path );
555
556
556
- return applyContributors (builder , method , args );
557
+ return applyContributors (builder , annotatedMethod , args );
557
558
}
558
559
559
560
private static UriComponentsBuilder getBaseUrlToUse (@ Nullable UriComponentsBuilder baseUrl ) {
@@ -587,13 +588,12 @@ private static String getClassMapping(Class<?> controllerType) {
587
588
return getPathMapping (mapping , controllerType .getName ());
588
589
}
589
590
590
- private static String getMethodMapping (Method method ) {
591
- Assert .notNull (method , "'method' must not be null" );
592
- RequestMapping requestMapping = AnnotatedElementUtils .findMergedAnnotation (method , RequestMapping .class );
591
+ private static String getMethodMapping (AnnotatedMethod annotatedMethod ) {
592
+ RequestMapping requestMapping = annotatedMethod .getMethodAnnotation (RequestMapping .class );
593
593
if (requestMapping == null ) {
594
- throw new IllegalArgumentException ("No @RequestMapping on: " + method .toGenericString ());
594
+ throw new IllegalArgumentException ("No @RequestMapping on: " + annotatedMethod . getMethod () .toGenericString ());
595
595
}
596
- return getPathMapping (requestMapping , method .toGenericString ());
596
+ return getPathMapping (requestMapping , annotatedMethod . getMethod () .toGenericString ());
597
597
}
598
598
599
599
private static String getPathMapping (RequestMapping requestMapping , String source ) {
@@ -628,10 +628,12 @@ else if (methods.size() > 1) {
628
628
}
629
629
}
630
630
631
- private static UriComponentsBuilder applyContributors (UriComponentsBuilder builder , Method method , Object ... args ) {
631
+ private static UriComponentsBuilder applyContributors (UriComponentsBuilder builder ,
632
+ AnnotatedMethod annotatedMethod , Object ... args ) {
633
+
632
634
CompositeUriComponentsContributor contributor = getUriComponentsContributor ();
633
635
634
- int paramCount = method . getParameterCount () ;
636
+ int paramCount = annotatedMethod . getMethodParameters (). length ;
635
637
int argCount = args .length ;
636
638
if (paramCount != argCount ) {
637
639
throw new IllegalArgumentException ("Number of method parameters " + paramCount +
@@ -640,7 +642,7 @@ private static UriComponentsBuilder applyContributors(UriComponentsBuilder build
640
642
641
643
final Map <String , Object > uriVars = new HashMap <>();
642
644
for (int i = 0 ; i < paramCount ; i ++) {
643
- MethodParameter param = new SynthesizingMethodParameter ( method , i ) ;
645
+ MethodParameter param = annotatedMethod . getMethodParameters ()[ i ] ;
644
646
param .initParameterNameDiscovery (parameterNameDiscoverer );
645
647
contributor .contributeMethodArgument (param , args [i ], builder , uriVars );
646
648
}
0 commit comments