Search in sources :

Example 36 with AnnotationAttributes

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

the class ImportAwareTests method indirectlyAnnotatedWithImport.

@Test
public void indirectlyAnnotatedWithImport() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(IndirectlyImportingConfig.class);
    ctx.refresh();
    assertThat(ctx.getBean("importedConfigBean")).isNotNull();
    ImportedConfig importAwareConfig = ctx.getBean(ImportedConfig.class);
    AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
    assertThat(importMetadata).isNotNull();
    assertThat(importMetadata.getClassName()).isEqualTo(IndirectlyImportingConfig.class.getName());
    AnnotationAttributes enableAttribs = AnnotationConfigUtils.attributesFor(importMetadata, EnableImportedConfig.class);
    String foo = enableAttribs.getString("foo");
    assertThat(foo).isEqualTo("xyz");
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) AnnotationMetadata(org.springframework.core.type.AnnotationMetadata) StandardAnnotationMetadata(org.springframework.core.type.StandardAnnotationMetadata) Test(org.junit.jupiter.api.Test)

Example 37 with AnnotationAttributes

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

the class MongoRepositoryConfigurationExtension method postProcess.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource)
	 */
@Override
public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {
    AnnotationAttributes attributes = config.getAttributes();
    builder.addPropertyReference("mongoOperations", attributes.getString("mongoTemplateRef"));
    builder.addPropertyValue("createIndexesForQueryMethods", attributes.getBoolean("createIndexesForQueryMethods"));
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

Example 38 with AnnotationAttributes

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

the class ReactiveMongoRepositoryConfigurationExtension method postProcess.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource)
	 */
@Override
public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {
    AnnotationAttributes attributes = config.getAttributes();
    builder.addPropertyReference("reactiveMongoOperations", attributes.getString("reactiveMongoTemplateRef"));
    builder.addPropertyValue("createIndexesForQueryMethods", attributes.getBoolean("createIndexesForQueryMethods"));
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

Example 39 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project cuba by cuba-platform.

the class OnConfigPropertyCondition method matches.

@Override
public boolean matches(@Nonnull ConditionContext context, @Nonnull AnnotatedTypeMetadata metadata) {
    Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnAppProperty.class.getName());
    if (attributes != null) {
        String configPropertyName = (String) attributes.get("property");
        String configPropertyValue = (String) attributes.get("value");
        String configPropertyDefaultValue = (String) attributes.get("defaultValue");
        return isConditionSatisfied(configPropertyName, configPropertyValue, configPropertyDefaultValue);
    } else {
        Map<String, Object> valueMap = metadata.getAnnotationAttributes(ConditionalOnAppProperties.class.getName());
        if (valueMap == null) {
            return true;
        }
        AnnotationAttributes[] properties = (AnnotationAttributes[]) valueMap.get("value");
        for (AnnotationAttributes propertyCondition : properties) {
            String configPropertyName = (String) propertyCondition.get("property");
            String configPropertyValue = (String) propertyCondition.get("value");
            String configPropertyDefaultValue = (String) propertyCondition.get("defaultValue");
            if (!isConditionSatisfied(configPropertyName, configPropertyValue, configPropertyDefaultValue)) {
                return false;
            }
        }
    }
    return true;
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

Example 40 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project leopard by tanhaichao.

the class OptionScanner method getValue.

protected String getValue(BeanDefinition beanDefinition) {
    AnnotationMetadata metadata = ((AnnotatedBeanDefinition) beanDefinition).getMetadata();
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(Option.class.getName(), false));
    return attributes.getString("value");
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) AnnotationMetadata(org.springframework.core.type.AnnotationMetadata)

Aggregations

AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)90 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)4 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 PropertySourcesProcessor (com.ctrip.framework.apollo.spring.config.PropertySourcesProcessor)2 SpringValueDefinitionProcessor (com.ctrip.framework.apollo.spring.property.SpringValueDefinitionProcessor)2 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