Java 类org.springframework.core.type.AnnotationMetadata 实例源码

项目:mybatisplus-boot-starter    文件:MybatisPlusAutoConfiguration.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

    logger.debug("Searching for mappers annotated with @Mapper");

    ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);

    try {
        if (this.resourceLoader != null) {
            scanner.setResourceLoader(this.resourceLoader);
        }

        List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
        if (logger.isDebugEnabled()) {
            for (String pkg : packages) {
                logger.debug("Using auto-configuration base package '" + pkg + "'");
            }
        }

        scanner.setAnnotationClass(Mapper.class);
        scanner.registerFilters();
        scanner.doScan(StringUtils.toStringArray(packages));
    } catch (IllegalStateException ex) {
        logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled." + ex);
    }
}
项目:RestyPass    文件:RestyProxyRegister.java   
/**
 * Gets base packages.
 *
 * @param importingClassMetadata the importing class metadata
 * @return the base packages
 */
protected Set<String> getBasePackages(AnnotationMetadata importingClassMetadata) {
    Map<String, Object> attributes = importingClassMetadata
            .getAnnotationAttributes(EnableRestyPass.class.getCanonicalName());

    Set<String> basePackages = new HashSet<>();
    if (StringUtils.hasText((String) attributes.get("value"))) {
        basePackages.add((String) attributes.get("value"));
    }

    for (String pkg : (String[]) attributes.get("basePackages")) {
        if (StringUtils.hasText(pkg)) {
            basePackages.add(pkg);
        }
    }
    for (Class<?> clazz : (Class[]) attributes.get("basePackageClasses")) {
        basePackages.add(ClassUtils.getPackageName(clazz));
    }

    if (basePackages.isEmpty()) {
        basePackages.add(
                ClassUtils.getPackageName(importingClassMetadata.getClassName()));
    }
    return basePackages;
}
项目:composed-task-runner    文件:StepBeanDefinitionRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
        BeanDefinitionRegistry registry) {
    ComposedTaskProperties properties = composedTaskProperties();
    TaskParser taskParser = new TaskParser("bean-registration",
            properties.getGraph(), false, true);
    Map<String, Integer> taskSuffixMap = getTaskApps(taskParser);
    for (String taskName : taskSuffixMap.keySet()) {
        //handles the possibility that multiple instances of
        // task definition exist in a composed task
        for (int taskSuffix = 0; taskSuffixMap.get(taskName) >= taskSuffix; taskSuffix++) {
            BeanDefinitionBuilder builder = BeanDefinitionBuilder
                    .rootBeanDefinition(ComposedTaskRunnerStepFactory.class);
            builder.addConstructorArgValue(properties);
            builder.addConstructorArgValue(String.format("%s_%s",
                    taskName, taskSuffix));
            builder.addPropertyValue("taskSpecificProps",
                    getPropertiesForTask(taskName, properties));
            builder.addPropertyValue("arguments", properties.getComposedTaskArguments());

            registry.registerBeanDefinition(String.format("%s_%s",
                    taskName, taskSuffix), builder.getBeanDefinition());
        }
    }
}
项目:configx    文件:EnableConfigServiceImportSelector.java   
@Override
        public void registerBeanDefinitions(AnnotationMetadata metadata,
                                            BeanDefinitionRegistry registry) {
            MultiValueMap<String, Object> attributes = metadata
                    .getAllAnnotationAttributes(
                            EnableConfigService.class.getName(), false);
            Object[] type = attributes == null ? null
                    : (Object[]) attributes.getFirst("converters");
            if (type == null || type.length == 0) {
                return;
            }

            List<Class<?>> types = collectClasses(attributes.get("converters"));
//            for (Class<?> type : types) {
//                String name = type.getName();
//                if (!registry.containsBeanDefinition(name)) {
//                    registerBeanDefinition(registry, type, name);
//                }
//            }

            registerConverters(registry, types);
        }
项目:xm-commons    文件:LepServicesRegistrar.java   
/**
 * {@inheritDoc}
 */
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    LepServiceProvider scanner = getScanner();
    Set<String> basePackages = getBasePackages(importingClassMetadata);
    for (String basePackage : basePackages) {
        Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage);

        for (BeanDefinition candidateComponent : candidateComponents) {
            if (candidateComponent instanceof AnnotatedBeanDefinition) {
                AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent;
                AnnotationMetadata annotationMetadata = beanDefinition.getMetadata();

                Map<String, Object> attributes = annotationMetadata
                    .getAnnotationAttributes(LepService.class.getCanonicalName());

                registerLepService(registry, annotationMetadata, attributes);
            }
        }
    }
}
项目:Your-Microservice    文件:YourMicroserviceBeanConfiguration.java   
/**
 * selectImports
 * <p>
 * Provides a configuration list of additional Import which should be performed to
 * implement the applicable configuration.
 *
 * @param importingClassMetadata Annotations Metadata to use to construct Imports.
 * @return String Array of Configuration Imports.
 */
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
    AnnotationAttributes attributes =
            AnnotationAttributes.fromMap(
                    importingClassMetadata.getAnnotationAttributes(EnableYourMicroservice.class.getName(), false));
    String environmentType = attributes.getString("environmentType");
    LOGGER.info("Using specified EnvironmentType:[{}]", environmentType);
    /**
     *  Create our necessary Imports.
     */
    return new String[]{
            YourMicroserviceEnvironmentConfiguration.class.getName()

            // Add Security Import as Applicable ...
    };

}
项目:mango-spring-boot-starter    文件:MangoDaoAutoCreator.java   
private List<Class<?>> findMangoDaoClasses(String packages) {
    try {
        List<Class<?>> daos = new ArrayList<Class<?>>();
        ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
        MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
        for (String locationPattern : getLocationPattern(packages)) {
            Resource[] rs = resourcePatternResolver.getResources(locationPattern);
            for (Resource r : rs) {
                MetadataReader reader = metadataReaderFactory.getMetadataReader(r);
                AnnotationMetadata annotationMD = reader.getAnnotationMetadata();
                if (annotationMD.hasAnnotation(DB.class.getName())) {
                    ClassMetadata clazzMD = reader.getClassMetadata();
                    daos.add(Class.forName(clazzMD.getClassName()));
                }
            }
        }
        return daos;
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
项目:xm-ms-entity    文件:LepServicesRegistrar.java   
/**
 * {@inheritDoc}
 */
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    LepServiceProvider scanner = getScanner();
    Set<String> basePackages = getBasePackages(importingClassMetadata);
    for (String basePackage : basePackages) {
        Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage);

        for (BeanDefinition candidateComponent : candidateComponents) {
            if (candidateComponent instanceof AnnotatedBeanDefinition) {
                AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent;
                AnnotationMetadata annotationMetadata = beanDefinition.getMetadata();

                Map<String, Object> attributes = annotationMetadata
                    .getAnnotationAttributes(LepService.class.getCanonicalName());

                registerLepService(registry, annotationMetadata, attributes);
            }
        }
    }
}
项目:lams    文件:AnnotationBeanNameGenerator.java   
/**
 * Derive a bean name from one of the annotations on the class.
 * @param annotatedDef the annotation-aware bean definition
 * @return the bean name, or {@code null} if none is found
 */
protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) {
    AnnotationMetadata amd = annotatedDef.getMetadata();
    Set<String> types = amd.getAnnotationTypes();
    String beanName = null;
    for (String type : types) {
        AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(amd, type);
        if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) {
            Object value = attributes.get("value");
            if (value instanceof String) {
                String strVal = (String) value;
                if (StringUtils.hasLength(strVal)) {
                    if (beanName != null && !strVal.equals(beanName)) {
                        throw new IllegalStateException("Stereotype annotations suggest inconsistent " +
                                "component names: '" + beanName + "' versus '" + strVal + "'");
                    }
                    beanName = strVal;
                }
            }
        }
    }
    return beanName;
}
项目:lams    文件:ConfigurationClassBeanDefinitionReader.java   
/**
 * Register the {@link Configuration} class itself as a bean definition.
 */
private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass) {
    AnnotationMetadata metadata = configClass.getMetadata();
    BeanDefinition configBeanDef = new AnnotatedGenericBeanDefinition(metadata);
    if (ConfigurationClassUtils.checkConfigurationClassCandidate(configBeanDef, this.metadataReaderFactory)) {
        String configBeanName = this.importBeanNameGenerator.generateBeanName(configBeanDef, this.registry);
        this.registry.registerBeanDefinition(configBeanName, configBeanDef);
        configClass.setBeanName(configBeanName);
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Registered bean definition for imported @Configuration class %s", configBeanName));
        }
    }
    else {
        this.problemReporter.error(
                new InvalidConfigurationImportProblem(metadata.getClassName(), configClass.getResource(), metadata));
    }
}
项目:spring-backend-boilerplate    文件:EnableMenuImportSelector.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes enableMenu = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableMenu.class
                                                                                                            .getName(),
                                                                                                    false));

    if (enableMenu != null) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(DefaultMenuPlugin.class);
        AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();

        MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
        mutablePropertyValues.add("extensionPointId", enableMenu.getString("extensionPointId"));
        mutablePropertyValues.add("pluginId", enableMenu.getString("pluginId"));
        mutablePropertyValues.add("menu", toMenu(enableMenu.getAnnotationArray("menu")));
        beanDefinition.setPropertyValues(mutablePropertyValues);

        registry.registerBeanDefinition("menuPlugin:" + enableMenu.getString("pluginId"), beanDefinition);
    }
}
项目:holon-datastore-jpa    文件:JpaDatastoreAutoConfigurationRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
    // Register JPA Datastore (transactional)
    if (beanFactory instanceof ListableBeanFactory) {
        String[] emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
                (ListableBeanFactory) beanFactory, EntityManagerFactory.class, true, false);
        if (emfBeanNames == null || emfBeanNames.length == 0) {
            emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) beanFactory,
                    AbstractEntityManagerFactoryBean.class, true, false);
        }
        if (emfBeanNames != null && emfBeanNames.length == 1) {
            String emfBeanName = (emfBeanNames[0].startsWith("&")) ? emfBeanNames[0].substring(1) : emfBeanNames[0];
            JpaDatastoreRegistrar.registerDatastore(registry, null, PrimaryMode.AUTO, emfBeanName, true, false,
                    beanClassLoader);
        }
    }
}
项目:mapper-boot-starter    文件:MapperAutoConfiguration.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

    logger.debug("Searching for mappers annotated with @Mapper");

    ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
    scanner.setMapperProperties(environment);
    try {
        if (this.resourceLoader != null) {
            scanner.setResourceLoader(this.resourceLoader);
        }

        List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
        if (logger.isDebugEnabled()) {
            for (String pkg : packages) {
                logger.debug("Using auto-configuration base package '{}'", pkg);
            }
        }

        scanner.setAnnotationClass(Mapper.class);
        scanner.registerFilters();
        scanner.doScan(StringUtils.toStringArray(packages));
    } catch (IllegalStateException ex) {
        logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
    }
}
项目:holon-core    文件:BeanFactoryScopeRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {

    Map<String, Object> attributes = annotationMetadata.getAnnotationAttributes(EnableBeanContext.class.getName());
    if (attributes == null) {
        return;
    }

    boolean lookupByType = (boolean) attributes.get("lookupByType");

    // check environment
    if (environment.containsProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME)) {
        lookupByType = environment.getProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME, Boolean.class);
    }

    // register post processor
    if (!registry.containsBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME)) {
        BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder
                .genericBeanDefinition(BeanFactoryScopePostProcessor.class).setDestroyMethodName("unregister")
                .addPropertyValue("lookupByType", lookupByType).setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        registry.registerBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME,
                postProcessorBuilder.getBeanDefinition());
    }
}
项目:holon-core    文件:AbstractRepeatableAnnotationRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
    // Single annotation
    if (annotationMetadata.isAnnotated(repeatableAnnotation.getName())) {
        register(annotationMetadata.getAnnotationAttributes(repeatableAnnotation.getName()), registry, false);
    } else if (annotationMetadata.isAnnotated(repeatableAnnotationContainer.getName())) {
        // Multiple annotations
        Map<String, Object> attributes = annotationMetadata
                .getAnnotationAttributes(repeatableAnnotationContainer.getName());
        AnnotationAttributes[] repetitions = (AnnotationAttributes[]) attributes.get("value");
        if (repetitions != null) {
            for (AnnotationAttributes repetition : repetitions) {
                register(repetition, registry, true);
            }
        }
    }
}
项目:holon-datastore-jdbc    文件:JdbcDatastoreRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
    if (!annotationMetadata.isAnnotated(EnableJdbcDatastore.class.getName())) {
        // ignore call from sub classes
        return;
    }

    Map<String, Object> attributes = annotationMetadata
            .getAnnotationAttributes(EnableJdbcDatastore.class.getName());

    // attributes
    String dataContextId = BeanRegistryUtils.getAnnotationValue(attributes, "dataContextId", null);
    PrimaryMode primaryMode = BeanRegistryUtils.getAnnotationValue(attributes, "primary", PrimaryMode.AUTO);
    String dataSourceReference = BeanRegistryUtils.getAnnotationValue(attributes, "dataSourceReference", null);

    String dataSourceBeanName = dataSourceReference;
    if (dataSourceBeanName == null) {
        dataSourceBeanName = BeanRegistryUtils.buildBeanName(dataContextId,
                EnableDataSource.DEFAULT_DATASOURCE_BEAN_NAME);
    }

    registerDatastore(registry, getEnvironment(), dataContextId, primaryMode, dataSourceBeanName,
            BeanRegistryUtils.getAnnotationValue(attributes, "platform", DatabasePlatform.NONE),
            BeanRegistryUtils.getAnnotationValue(attributes, "transactional", true), beanClassLoader);
}
项目:holon-jdbc    文件:DataSourceRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {

    if (!annotationMetadata.isAnnotated(EnableDataSource.class.getName())) {
        // ignore call from sub classes
        return;
    }

    Map<String, Object> attributes = annotationMetadata.getAnnotationAttributes(EnableDataSource.class.getName());

    // Annotation values
    String dataContextId = BeanRegistryUtils.getAnnotationValue(attributes, "dataContextId", null);
    PrimaryMode primaryMode = BeanRegistryUtils.getAnnotationValue(attributes, "primary", PrimaryMode.AUTO);
    boolean registerTransactionManager = BeanRegistryUtils.getAnnotationValue(attributes,
            "enableTransactionManager", false);

    String dsBeanName = registerDataSource(getEnvironment(), registry, dataContextId, primaryMode);

    // Transaction manager

    if (registerTransactionManager) {
        registerDataSourceTransactionManager(registry, dsBeanName, dataContextId, primaryMode);
    }

}
项目:holon-jdbc    文件:DataSourcesTransactionManagerAutoConfigurationRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

    if (beanFactory instanceof ListableBeanFactory) {

        String[] dataSourceBeanNames = ((ListableBeanFactory) beanFactory).getBeanNamesForType(DataSource.class,
                false, true);
        if (dataSourceBeanNames != null) {
            for (String dataSourceBeanName : dataSourceBeanNames) {
                BeanDefinition bd = registry.getBeanDefinition(dataSourceBeanName);
                if (bd instanceof DataContextBoundBeanDefinition) {
                    DataSourceRegistrar.registerDataSourceTransactionManager(registry, dataSourceBeanName,
                            ((DataContextBoundBeanDefinition) bd).getDataContextId().orElse(null),
                            PrimaryMode.AUTO);
                }
            }
        }

    }

}
项目:alfresco-remote-api    文件:PublicApiHttpClient.java   
private Pair<String, String> getRelationCollectionInfo(Class<?> resourceClass) throws IOException
{
    AnnotationMetadata annotationMetaData = getAnnotationMetadata(resourceClass.getCanonicalName());
    if (annotationMetaData.isConcrete() && annotationMetaData.isIndependent())
    {
        if (annotationMetaData.getAnnotationTypes().contains(RelationshipResource.class.getCanonicalName()))
        {
            Map<String, Object> attrs = annotationMetaData.getAnnotationAttributes(RelationshipResource.class.getName());
            String relationshipCollectionName = (String) attrs.get("name");
            Class<?> entityResource = (Class<?>) attrs.get("entityResource");

            String entityCollectionName = getEntityCollectionInfo(entityResource.getCanonicalName());

            Pair<String, String> ret = new Pair<String, String>(entityCollectionName, relationshipCollectionName);
            return ret;
        }
        else
        {
            return null;
        }
    }
    else
    {
        throw new AlfrescoRuntimeException("");
    }
}
项目:alfresco-remote-api    文件:PublicApiHttpClient.java   
private String getEntityCollectionInfo(String className) throws IOException
{
    AnnotationMetadata annotationMetaData = getAnnotationMetadata(className);
    if (annotationMetaData.isConcrete() && annotationMetaData.isIndependent())
    {
        if (annotationMetaData.getAnnotationTypes().contains(EntityResource.class.getCanonicalName()))
        {
            Map<String, Object> attrs = annotationMetaData.getAnnotationAttributes(EntityResource.class.getName());
            return (String) attrs.get("name");
        }
        else
        {
            return null;
        }
    }
    else
    {
        throw new AlfrescoRuntimeException("");
    }
}
项目:apollo-custom    文件:ApolloConfigRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
  AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata
      .getAnnotationAttributes(EnableApolloConfig.class.getName()));
  String[] namespaces = attributes.getStringArray("value");
  int order = attributes.getNumber("order");
  PropertySourcesProcessor.addNamespaces(Lists.newArrayList(namespaces), order);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
      PropertySourcesPlaceholderConfigurer.class);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesProcessor.class.getName(),
      PropertySourcesProcessor.class);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
      ApolloAnnotationProcessor.class);
}
项目:springboot-analysis    文件:ConsumerRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.addIncludeFilter(new AnnotationTypeFilter(Consumer.class));
    provider.addIncludeFilter(new AssignableTypeFilter(IConsumer.class));
    Set<BeanDefinition> beanDefinitionSet = provider.findCandidateComponents("spring.study.componentprovider.bean");

    for(BeanDefinition beanDefinition : beanDefinitionSet) {
        String beanName = beanNameGenerator.generateBeanName(beanDefinition, registry);
        if(!registry.containsBeanDefinition(beanName)) {
            registry.registerBeanDefinition(beanName, beanDefinition);
            registry.registerBeanDefinition("11", beanDefinition);
        }
    }

}
项目:configx    文件:EnableMessageSourceImportSelector.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
    MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(EnableMessageSource.class.getName(), false);
    boolean fallbackToSystemLocale = (boolean) (attributes != null ? attributes.getFirst("fallbackToSystemLocale") : false);
    String[] basenames = (String[]) (attributes != null ? attributes.getFirst("basenames") : null);

    BeanDefinitionBuilder bean = BeanDefinitionBuilder.genericBeanDefinition(ConfigMessageSourceConfigurer.class);
    bean.addPropertyValue("fallbackToSystemLocale", fallbackToSystemLocale);
    if (basenames != null && basenames.length > 0) {
        bean.addPropertyValue("basenames", basenames);
    }
    registry.registerBeanDefinition(ConfigMessageSourceConfigurer.class.getName(), bean.getBeanDefinition());
}
项目:spring-seed    文件:SpringSeedJpa.java   
@Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableSpringSeedJpa.class.getName()));
        String propertyPrefix = attributes.getString("propertyPrefix");
        String beanNamePrefix =  attributes.getString("beanNamePrefix");
        Class<?>[] entityPackages = attributes.getClassArray("baseEntityClasses");

/*
        //There are two ways to register bean dynamically in Spring.
        DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)this.beanFactory;

        DataSource dataSource = JpaBuilderUtil.newDataSource(environment, prefix);
        beanFactory.registerSingleton(prefix + DataSource.class.getSimpleName(), dataSource);

        EntityManagerFactory entityManagerFactory = JpaBuilderUtil.newEntityManagerFactory(dataSource, entityPackages);
        beanFactory.registerSingleton(prefix + "entityManager", entityManagerFactory);

        PlatformTransactionManager platformTransactionManager = JpaBuilderUtil.newPlatformTransactionManager(entityManagerFactory);
        beanFactory.registerSingleton(prefix + "transactionManager", platformTransactionManager);
*/

        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Dbcp2DataSourceFactoryBean.class)
            .addPropertyValue("prefix", propertyPrefix)
            .addPropertyValue("environment", this.environment)
            .setDestroyMethodName("close");
        String dataSourceName = beanNamePrefix.isEmpty()? "dataSource": beanNamePrefix + "DataSource";
        registry.registerBeanDefinition(dataSourceName, builder.getBeanDefinition());

        BeanDefinitionBuilder builderEntity = BeanDefinitionBuilder.genericBeanDefinition(EntityManagerFactoryFactoryBean.class)
            .addPropertyReference("dataSource", dataSourceName)
            .addPropertyValue("entityPackages", entityPackages);
        String entityManagerFactoryName = beanNamePrefix.isEmpty()? "entityManagerFactory": beanNamePrefix + "EntityManagerFactory";
        registry.registerBeanDefinition(entityManagerFactoryName, builderEntity.getBeanDefinition());

        BeanDefinitionBuilder builderTrans = BeanDefinitionBuilder.genericBeanDefinition(JpaTransactionManagerFactoryBean.class)
            .addPropertyReference("entityManagerFactory",entityManagerFactoryName);
        String transactionManagerName = beanNamePrefix.isEmpty()? "transactionManager": beanNamePrefix + "TransactionManager";
        registry.registerBeanDefinition(transactionManagerName, builderTrans.getBeanDefinition());
    }
项目:JRediClients    文件:RedissonHttpSessionConfiguration.java   
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableRedissonHttpSession.class.getName());
    AnnotationAttributes attrs = AnnotationAttributes.fromMap(map);
    keyPrefix = attrs.getString("keyPrefix");
    maxInactiveIntervalInSeconds = attrs.getNumber("maxInactiveIntervalInSeconds");
}
项目:xm-commons    文件:LepServicesRegistrar.java   
private void registerLepService(BeanDefinitionRegistry registry,
                                AnnotationMetadata annotationMetadata,
                                Map<String, Object> attributes) {
    // has a default, won't be null
    boolean primary = (Boolean) attributes.get("primary");

    String className = annotationMetadata.getClassName();
    BeanDefinitionBuilder definition = BeanDefinitionBuilder
        .genericBeanDefinition(LepServiceFactoryBean.class);
    definition.addPropertyValue("type", className);
    definition.addPropertyValue("annotationMetadata", annotationMetadata);
    definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);

    AbstractBeanDefinition beanDefinition = definition.getBeanDefinition();
    beanDefinition.setPrimary(primary);

    String name = getBeanName(annotationMetadata, attributes);
    String alias = name + LepService.class.getSimpleName();
    String qualifier = getQualifier(attributes);
    if (StringUtils.hasText(qualifier)) {
        alias = qualifier;
    }

    BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, name,
                                                           new String[] {alias});
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
}
项目:xm-commons    文件:LepServicesRegistrar.java   
private static String getBeanName(AnnotationMetadata annotationMetadata, Map<String, Object> attributes) {
    // name & value are aliases
    String beanName = (String) attributes.get("value");
    if (!StringUtils.isEmpty(beanName)) {
        return beanName;
    } else {
        // generate bean name from class name
        String shortName = ClassUtils.getShortName(annotationMetadata.getClassName());
        return StringUtils.uncapitalize(shortName);
    }
}
项目:vertx-spring    文件:VertxConfigurationImportSelector.java   
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {

    Map<String, Object> attributes = importingClassMetadata.getAnnotationAttributes(EnableVertx.class.getName());
    boolean deployVerticles = (boolean) attributes.getOrDefault("deployVerticles", Boolean.TRUE);

    if (deployVerticles) {
        return new String[] { VertxConfiguration.class.getName(), VerticleDeploymentConfiguration.class.getName() };
    } else {
        return new String[] { VertxConfiguration.class.getName() };
    }
}
项目:spring-data-generator    文件:ScanningConfigurationSupport.java   
public ScanningConfigurationSupport(AnnotationMetadata annotationMetadata, AnnotationAttributes attributes, Environment environment){
    Assert.notNull(environment, "Environment must not be null!");
    Assert.notNull(environment, "AnnotationMetadata must not be null!");
    this.environment = environment;
    this.attributes = attributes;
    this.annotationMetadata = annotationMetadata;
    this.entityPackage = this.attributes.getStringArray("entityPackage");
    this.onlyAnnotations = this.attributes.getBoolean("onlyAnnotations");
}
项目:wamp2spring    文件:WampConfiguration.java   
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> attributes = AnnotationAttributes.fromMap(importMetadata
            .getAnnotationAttributes(EnableWamp.class.getName(), false));
    if (attributes != null) {
        Feature[] disableFeatures = (Feature[]) attributes.get("disable");
        if (disableFeatures != null) {
            for (Feature disableFeature : disableFeatures) {
                this.features.disable(disableFeature);
            }
        }
    }
}
项目:druid-spring-boot    文件:DruidDataSourceConfiguration.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
    resolver.getSubProperties(EMPTY).keySet().stream()
            .map(key -> key.substring(0, key.indexOf(POINT)))
            .distinct()
            .forEach(dataSourceName -> {
                // 注册 BeanDefinition
                String camelName = CharMatcher.separatedToCamel().apply(dataSourceName);
                registry.registerBeanDefinition(camelName, genericDruidBeanDefinition());
                // 注册以 DataSource 为后缀的别名
                if (!camelName.toLowerCase().endsWith(BEAN_SUFFIX.toLowerCase())) {
                    registry.registerAlias(camelName, camelName + BEAN_SUFFIX);
                }
            });
}
项目:druid-spring-boot    文件:DruidDataSourceConfiguration.java   
@Override
public String[] selectImports(AnnotationMetadata metadata) {
    Map<String, Object> properties = resolver.getSubProperties(EMPTY);
    Builder<Class<?>> imposts = Stream.<Class<?>>builder().add(DruidDataSourceBeanPostProcessor.class);
    imposts.add(properties.isEmpty() ? SingleDataSourceRegistrar.class : DynamicDataSourceRegistrar.class);
    return imposts.build().map(Class::getName).toArray(String[]::new);
}
项目:Your-Microservice    文件:YourMicroserviceBeanConfiguration.java   
/**
 * setImportMetadata
 *
 * @param importMetadata Annotations Metadata to validate...
 */
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableYourMicroservice.class.getName());
    this.enableYourMicroservice = AnnotationAttributes.fromMap(map);
    if (this.enableYourMicroservice == null) {
        String message =
                "@EnableYourMicroservice is not present on importing class " + importMetadata.getClassName();
        LOGGER.error(message);
        throw new IllegalArgumentException(message);
    }
}
项目:xm-ms-entity    文件:LepServicesRegistrar.java   
private void registerLepService(BeanDefinitionRegistry registry,
                                AnnotationMetadata annotationMetadata,
                                Map<String, Object> attributes) {
    // has a default, won't be null
    boolean primary = (Boolean) attributes.get("primary");

    String className = annotationMetadata.getClassName();
    BeanDefinitionBuilder definition = BeanDefinitionBuilder
        .genericBeanDefinition(LepServiceFactoryBean.class);
    definition.addPropertyValue("type", className);
    definition.addPropertyValue("annotationMetadata", annotationMetadata);
    definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);

    AbstractBeanDefinition beanDefinition = definition.getBeanDefinition();
    beanDefinition.setPrimary(primary);

    String name = getBeanName(annotationMetadata, attributes);
    String alias = name + LepService.class.getSimpleName();
    String qualifier = getQualifier(attributes);
    if (StringUtils.hasText(qualifier)) {
        alias = qualifier;
    }

    BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, name,
                                                           new String[] {alias});
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
}
项目:xm-ms-entity    文件:LepServicesRegistrar.java   
private static String getBeanName(AnnotationMetadata annotationMetadata, Map<String, Object> attributes) {
    // name & value are aliases
    String beanName = (String) attributes.get("value");
    if (!StringUtils.isEmpty(beanName)) {
        return beanName;
    } else {
        // generate bean name from class name
        String shortName = ClassUtils.getShortName(annotationMetadata.getClassName());
        return StringUtils.uncapitalize(shortName);
    }
}
项目:azure-spring-boot    文件:TestAutoConfigurationPackageRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata,
                                    BeanDefinitionRegistry registry) {
    final AnnotationAttributes attributes = AnnotationAttributes
            .fromMap(metadata.getAnnotationAttributes(
                    TestAutoConfigurationPackage.class.getName(), true));
    AutoConfigurationPackages.register(registry,
            ClassUtils.getPackageName(attributes.getString("value")));
}
项目:spring-boot-autoconfigure    文件:SpringProfileAutoConfiguration.java   
@Override
public String[] selectImports(AnnotationMetadata metadata) {
    Map<String, Object> properties = resolver.getSubProperties("");
    if (properties == null || properties.isEmpty()) {
        return new String[0];
    }
    return properties.values().stream()
            .filter(Objects::nonNull)
            .map(Objects::toString)
            .map(String::trim)
            .filter(s -> !s.isEmpty())
            .toArray(String[]::new);
}
项目:spring-data-snowdrop    文件:JpaWithSnowdropRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importMetadata, BeanDefinitionRegistry registry) {
  AnnotationAttributes attributes = AnnotationAttributes.fromMap(
          importMetadata.getAnnotationAttributes(JpaWithSnowdropConfiguration.class.getName(), false));
  if (attributes == null) {
    throw new IllegalArgumentException(
            "@JpaWithSnowdropConfiguration is not present on importing class " + importMetadata.getClassName());
  }
  registry.registerBeanDefinition(
          JpaRepositoryFactoryBeanSnowdropPostProcessor.class.getName(),
          buildPostProcessorDefinition(importMetadata, attributes)
  );
}
项目:appstatus-spring-boot-starter    文件:AbstractAppstatusImportAware.java   
@Override
public void setImportMetadata(AnnotationMetadata annotationMetadata) {
    Map<String, Object> map = annotationMetadata.getAnnotationAttributes(starterClass.getName());
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(map);

    initialize(attributes, new AppstatusConfigBuilder(attributes));
}
项目:lams    文件:AbstractAsyncConfiguration.java   
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    this.enableAsync = AnnotationAttributes.fromMap(
            importMetadata.getAnnotationAttributes(EnableAsync.class.getName(), false));
    Assert.notNull(this.enableAsync,
            "@EnableAsync is not present on importing class " + importMetadata.getClassName());
}