Search in sources :

Example 1 with AnnotationAttributes

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

the class OnEnabledEndpointElementCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(this.annotationType.getName()));
    String endpointName = annotationAttributes.getString("value");
    ConditionOutcome outcome = getEndpointOutcome(context, endpointName);
    if (outcome != null) {
        return outcome;
    }
    return getDefaultEndpointsOutcome(context);
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome)

Example 2 with AnnotationAttributes

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

the class OnEnabledEndpointCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(ConditionalOnEnabledEndpoint.class.getName()));
    String endpointName = annotationAttributes.getString("value");
    boolean enabledByDefault = annotationAttributes.getBoolean("enabledByDefault");
    ConditionOutcome outcome = determineEndpointOutcome(endpointName, enabledByDefault, context);
    if (outcome != null) {
        return outcome;
    }
    return determineAllEndpointsOutcome(context);
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome)

Example 3 with AnnotationAttributes

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

the class AutoConfigurationImportSelector method selectImports.

@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
    if (!isEnabled(annotationMetadata)) {
        return NO_IMPORTS;
    }
    try {
        AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader.loadMetadata(this.beanClassLoader);
        AnnotationAttributes attributes = getAttributes(annotationMetadata);
        List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);
        configurations = removeDuplicates(configurations);
        configurations = sort(configurations, autoConfigurationMetadata);
        Set<String> exclusions = getExclusions(annotationMetadata, attributes);
        checkExcludedClasses(configurations, exclusions);
        configurations.removeAll(exclusions);
        configurations = filter(configurations, autoConfigurationMetadata);
        fireAutoConfigurationImportEvents(configurations, exclusions);
        return configurations.toArray(new String[configurations.size()]);
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) IOException(java.io.IOException)

Example 4 with AnnotationAttributes

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

the class OverriddenMetaAnnotationAttributesTests method overriddenContextConfigurationLocationsAndInheritLocations.

@Test
public void overriddenContextConfigurationLocationsAndInheritLocations() throws Exception {
    Class<?> declaringClass = OverriddenMetaLocationsConfigTestCase.class;
    AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(declaringClass, ContextConfiguration.class);
    assertNotNull(descriptor);
    assertEquals(declaringClass, descriptor.getRootDeclaringClass());
    assertEquals(MetaLocationsConfig.class, descriptor.getComposedAnnotationType());
    assertEquals(ContextConfiguration.class, descriptor.getAnnotationType());
    assertNotNull(descriptor.getComposedAnnotation());
    assertEquals(MetaLocationsConfig.class, descriptor.getComposedAnnotationType());
    // direct access to annotation attributes:
    assertArrayEquals(new String[] { "foo.xml" }, descriptor.getAnnotation().locations());
    assertFalse(descriptor.getAnnotation().inheritLocations());
    // overridden attributes:
    AnnotationAttributes attributes = descriptor.getAnnotationAttributes();
    assertArrayEquals(new String[] { "bar.xml" }, attributes.getStringArray("locations"));
    assertTrue(attributes.getBoolean("inheritLocations"));
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Test(org.junit.Test)

Example 5 with AnnotationAttributes

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

the class OverriddenMetaAnnotationAttributesTests method overriddenContextConfigurationValue.

@Test
public void overriddenContextConfigurationValue() throws Exception {
    Class<?> declaringClass = OverriddenMetaValueConfigTestCase.class;
    AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(declaringClass, ContextConfiguration.class);
    assertNotNull(descriptor);
    assertEquals(declaringClass, descriptor.getRootDeclaringClass());
    assertEquals(MetaValueConfig.class, descriptor.getComposedAnnotationType());
    assertEquals(ContextConfiguration.class, descriptor.getAnnotationType());
    assertNotNull(descriptor.getComposedAnnotation());
    assertEquals(MetaValueConfig.class, descriptor.getComposedAnnotationType());
    // direct access to annotation value:
    assertArrayEquals(new String[] { "foo.xml" }, descriptor.getAnnotation().value());
    // overridden attribute:
    AnnotationAttributes attributes = descriptor.getAnnotationAttributes();
    // NOTE: we would like to be able to override the 'value' attribute; however,
    // Spring currently does not allow overrides for the 'value' attribute.
    // See SPR-11393 for related discussions.
    assertArrayEquals(new String[] { "foo.xml" }, attributes.getStringArray("value"));
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Test(org.junit.Test)

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