Example usage for org.springframework.core.annotation AnnotatedElementUtils findMergedAnnotation

List of usage examples for org.springframework.core.annotation AnnotatedElementUtils findMergedAnnotation

Introduction

In this page you can find the example usage for org.springframework.core.annotation AnnotatedElementUtils findMergedAnnotation.

Prototype

@Nullable
public static <A extends Annotation> A findMergedAnnotation(AnnotatedElement element, Class<A> annotationType) 

Source Link

Document

Find the first annotation of the specified annotationType within the annotation hierarchy above the supplied element , merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specified annotationType .

Usage

From source file:org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.java

private static String getMethodRequestMapping(Method method) {
    Assert.notNull(method, "'method' must not be null");
    RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
    if (requestMapping == null) {
        throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
    }//from  w  w w .j  av  a 2 s.  co m
    String[] paths = requestMapping.path();
    if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
        return "/";
    }
    if (paths.length > 1 && logger.isWarnEnabled()) {
        logger.warn("Multiple paths on method " + method.toGenericString() + ", using first one");
    }
    return paths[0];
}