Example usage for org.springframework.core.type AnnotationMetadata getAnnotationAttributes

List of usage examples for org.springframework.core.type AnnotationMetadata getAnnotationAttributes

Introduction

In this page you can find the example usage for org.springframework.core.type AnnotationMetadata getAnnotationAttributes.

Prototype

@Nullable
default Map<String, Object> getAnnotationAttributes(String annotationName, boolean classValuesAsString) 

Source Link

Document

Retrieve the attributes of the annotation of the given type, if any (i.e.

Usage

From source file:org.springframework.cloud.commons.util.SpringFactoryImportSelector.java

@Override
public String[] selectImports(AnnotationMetadata metadata) {
    if (!isEnabled()) {
        return new String[0];
    }/*from   w w w.ja va  2  s  . c  o m*/
    AnnotationAttributes attributes = AnnotationAttributes
            .fromMap(metadata.getAnnotationAttributes(this.annotationClass.getName(), true));

    Assert.notNull(attributes, "No " + getSimpleName() + " attributes found. Is " + metadata.getClassName()
            + " annotated with @" + getSimpleName() + "?");

    // Find all possible auto configuration classes, filtering duplicates
    List<String> factories = new ArrayList<>(new LinkedHashSet<>(
            SpringFactoriesLoader.loadFactoryNames(this.annotationClass, this.beanClassLoader)));

    if (factories.isEmpty() && !hasDefaultFactory()) {
        throw new IllegalStateException("Annotation @" + getSimpleName()
                + " found, but there are no implementations. Did you forget to include a starter?");
    }

    if (factories.size() > 1) {
        // there should only ever be one DiscoveryClient, but there might be more than
        // one factory
        log.warn("More than one implementation " + "of @" + getSimpleName()
                + " (now relying on @Conditionals to pick one): " + factories);
    }

    return factories.toArray(new String[factories.size()]);
}

From source file:org.springframework.cloud.netflix.hystrix.HystrixConfiguration.java

@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    this.enableHystrix = AnnotationAttributes
            .fromMap(importMetadata.getAnnotationAttributes(EnableHystrix.class.getName(), false));
    Assert.notNull(this.enableHystrix,
            "@EnableHystrix is not present on importing class " + importMetadata.getClassName());
}