Search in sources :

Example 16 with AnnotationAttributes

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

the class KeyValueRepositoryConfigurationExtension method getQueryType.

/**
 * Detects the query creator type to be used for the factory to set. Will lookup a {@link QueryCreatorType} annotation
 * on the {@code @Enable}-annotation or use {@link SpelQueryCreator} if not found.
 *
 * @param config
 * @return
 */
private static Class<?> getQueryType(AnnotationRepositoryConfigurationSource config) {
    AnnotationMetadata metadata = config.getEnableAnnotationMetadata();
    Map<String, Object> queryCreatorAnnotationAttributes = metadata.getAnnotationAttributes(QueryCreatorType.class.getName());
    if (queryCreatorAnnotationAttributes == null) {
        return KeyValuePartTreeQuery.class;
    }
    AnnotationAttributes queryCreatorAttributes = new AnnotationAttributes(queryCreatorAnnotationAttributes);
    return queryCreatorAttributes.getClass("repositoryQueryType");
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) KeyValuePartTreeQuery(org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery) AnnotationMetadata(org.springframework.core.type.AnnotationMetadata)

Example 17 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project spring-cloud-stream by spring-cloud.

the class BindingBeansRegistrar method registerBeanDefinitions.

@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes attrs = AnnotatedElementUtils.getMergedAnnotationAttributes(ClassUtils.resolveClassName(metadata.getClassName(), null), EnableBinding.class);
    for (Class<?> type : collectClasses(attrs, metadata.getClassName())) {
        if (!registry.containsBeanDefinition(type.getName())) {
            BindingBeanDefinitionRegistryUtils.registerBindingTargetBeanDefinitions(type, type.getName(), registry);
            BindingBeanDefinitionRegistryUtils.registerBindingTargetsQualifiedBeanDefinitions(ClassUtils.resolveClassName(metadata.getClassName(), null), type, registry);
        }
    }
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

Example 18 with AnnotationAttributes

use of org.springframework.core.annotation.AnnotationAttributes in project cloud-sea-towerman by huadahuang1983.

the class MapperScannerRegistrar method registerBeanDefinitions.

/**
 * {@inheritDoc}
 */
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes annoAttrs = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(MapperScan.class.getName()));
    ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
    // this check is needed in Spring 3.1
    if (resourceLoader != null) {
        scanner.setResourceLoader(resourceLoader);
    }
    Class<? extends Annotation> annotationClass = annoAttrs.getClass("annotationClass");
    if (!Annotation.class.equals(annotationClass)) {
        scanner.setAnnotationClass(annotationClass);
    }
    Class<?> markerInterface = annoAttrs.getClass("markerInterface");
    if (!Class.class.equals(markerInterface)) {
        scanner.setMarkerInterface(markerInterface);
    }
    Class<? extends BeanNameGenerator> generatorClass = annoAttrs.getClass("nameGenerator");
    if (!BeanNameGenerator.class.equals(generatorClass)) {
        scanner.setBeanNameGenerator(BeanUtils.instantiateClass(generatorClass));
    }
    @SuppressWarnings("rawtypes") Class<? extends MapperFactoryBean> mapperFactoryBeanClass = annoAttrs.getClass("factoryBean");
    if (!MapperFactoryBean.class.equals(mapperFactoryBeanClass)) {
        scanner.setMapperFactoryBean(BeanUtils.instantiateClass(mapperFactoryBeanClass));
    }
    scanner.setSqlSessionTemplateBeanName(annoAttrs.getString("sqlSessionTemplateRef"));
    scanner.setSqlSessionFactoryBeanName(annoAttrs.getString("sqlSessionFactoryRef"));
    List<String> basePackages = new ArrayList<String>();
    for (String pkg : annoAttrs.getStringArray("value")) {
        if (StringUtils.hasText(pkg)) {
            basePackages.add(parsePlaceHolder(pkg));
        }
    }
    for (String pkg : annoAttrs.getStringArray("basePackages")) {
        if (StringUtils.hasText(pkg)) {
            basePackages.add(parsePlaceHolder(pkg));
        }
    }
    for (Class<?> clazz : annoAttrs.getClassArray("basePackageClasses")) {
        basePackages.add(ClassUtils.getPackageName(clazz));
    }
    scanner.registerFilters();
    scanner.doScan(StringUtils.toStringArray(basePackages));
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) MapperFactoryBean(org.mybatis.spring.mapper.MapperFactoryBean) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) BeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator) ClassPathMapperScanner(org.mybatis.spring.mapper.ClassPathMapperScanner)

Example 19 with AnnotationAttributes

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

the class RedisHttpSessionConfiguration method setImportMetadata.

@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> attributeMap = importMetadata.getAnnotationAttributes(EnableRedisHttpSession.class.getName());
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
    this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds");
    String redisNamespaceValue = attributes.getString("redisNamespace");
    if (StringUtils.hasText(redisNamespaceValue)) {
        this.redisNamespace = this.embeddedValueResolver.resolveStringValue(redisNamespaceValue);
    }
    this.redisFlushMode = attributes.getEnum("redisFlushMode");
    String cleanupCron = attributes.getString("cleanupCron");
    if (StringUtils.hasText(cleanupCron)) {
        this.cleanupCron = cleanupCron;
    }
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

Example 20 with AnnotationAttributes

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

the class JdbcHttpSessionConfiguration method setImportMetadata.

@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> attributeMap = importMetadata.getAnnotationAttributes(EnableJdbcHttpSession.class.getName());
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
    this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds");
    String tableNameValue = attributes.getString("tableName");
    if (StringUtils.hasText(tableNameValue)) {
        this.tableName = this.embeddedValueResolver.resolveStringValue(tableNameValue);
    }
    String cleanupCron = attributes.getString("cleanupCron");
    if (StringUtils.hasText(cleanupCron)) {
        this.cleanupCron = cleanupCron;
    }
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes)

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