Search in sources :

Example 76 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project spring-boot by spring-projects.

the class OnJndiCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(ConditionalOnJndi.class.getName()));
    String[] locations = annotationAttributes.getStringArray("value");
    try {
        return getMatchOutcome(locations);
    } catch (NoClassDefFoundError ex) {
        return ConditionOutcome.noMatch(ConditionMessage.forCondition(ConditionalOnJndi.class).because("JNDI class not found"));
    }
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

Example 77 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project spring-boot by spring-projects.

the class ConfigurationPropertiesScanRegistrar method getPackagesToScan.

private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(ConfigurationPropertiesScan.class.getName()));
    String[] basePackages = attributes.getStringArray("basePackages");
    Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
    Set<String> packagesToScan = new LinkedHashSet<>(Arrays.asList(basePackages));
    for (Class<?> basePackageClass : basePackageClasses) {
        packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
    }
    if (packagesToScan.isEmpty()) {
        packagesToScan.add(ClassUtils.getPackageName(metadata.getClassName()));
    }
    packagesToScan.removeIf((candidate) -> !StringUtils.hasText(candidate));
    return packagesToScan;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

Example 78 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project spring-boot by spring-projects.

the class SpringBootConfigurationTests method proxyBeanMethodsIsEnabledByDefault.

@Test
void proxyBeanMethodsIsEnabledByDefault() {
    AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(DefaultSpringBootConfiguration.class, Configuration.class);
    assertThat(attributes.get("proxyBeanMethods")).isEqualTo(true);
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) Test(org.junit.jupiter.api.Test)

Example 79 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project spring-boot by spring-projects.

the class RequestPredicateFactoryTests method getDiscoveredOperationMethod.

private DiscoveredOperationMethod getDiscoveredOperationMethod(Class<?> source) {
    Method method = source.getDeclaredMethods()[0];
    AnnotationAttributes attributes = new AnnotationAttributes();
    attributes.put("produces", "application/json");
    return new DiscoveredOperationMethod(method, OperationType.READ, attributes);
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) DiscoveredOperationMethod(org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod) DiscoveredOperationMethod(org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod) Method(java.lang.reflect.Method)

Example 80 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project spring-boot by spring-projects.

the class ImportAutoConfigurationImportSelector method getExclusions.

@Override
protected Set<String> getExclusions(AnnotationMetadata metadata, AnnotationAttributes attributes) {
    Set<String> exclusions = new LinkedHashSet<>();
    Class<?> source = ClassUtils.resolveClassName(metadata.getClassName(), null);
    for (String annotationName : ANNOTATION_NAMES) {
        AnnotationAttributes merged = AnnotatedElementUtils.getMergedAnnotationAttributes(source, annotationName);
        Class<?>[] exclude = (merged != null) ? merged.getClassArray("exclude") : null;
        if (exclude != null) {
            for (Class<?> excludeClass : exclude) {
                exclusions.add(excludeClass.getName());
            }
        }
    }
    for (List<Annotation> annotations : getAnnotations(metadata).values()) {
        for (Annotation annotation : annotations) {
            String[] exclude = (String[]) AnnotationUtils.getAnnotationAttributes(annotation, true).get("exclude");
            if (!ObjectUtils.isEmpty(exclude)) {
                exclusions.addAll(Arrays.asList(exclude));
            }
        }
    }
    exclusions.addAll(getExcludeAutoConfigurationsProperty());
    return exclusions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) Annotation(java.lang.annotation.Annotation)

Aggregations

AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)89 Test (org.junit.jupiter.api.Test)17 ArrayList (java.util.ArrayList)8 LinkedHashSet (java.util.LinkedHashSet)7 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)7 Annotation (java.lang.annotation.Annotation)6 Method (java.lang.reflect.Method)6 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)3 ConditionOutcome (org.springframework.boot.autoconfigure.condition.ConditionOutcome)3 StandardAnnotationMetadata (org.springframework.core.type.StandardAnnotationMetadata)3 DubboReference (org.apache.dubbo.config.annotation.DubboReference)2 ReferenceBean (org.apache.dubbo.config.spring.ReferenceBean)2 Test (org.junit.Test)2 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)2 BeanNameGenerator (org.springframework.beans.factory.support.BeanNameGenerator)2 DiscoveredOperationMethod (org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod)2 ContextConfiguration (org.springframework.test.context.ContextConfiguration)2