当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationAttributes.getClass方法代码示例

本文整理汇总了Java中org.springframework.core.annotation.AnnotationAttributes.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationAttributes.getClass方法的具体用法?Java AnnotationAttributes.getClass怎么用?Java AnnotationAttributes.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.core.annotation.AnnotationAttributes的用法示例。


在下文中一共展示了AnnotationAttributes.getClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
@Override
protected void initialize(AnnotationAttributes attributes, AppstatusConfigBuilder builder) {
    this.configuration = builder.set("batch.logInterval", "logInterval")
                                .set("batch.zombieInterval", "zombieInterval")
                                .build();

    this.tableName = attributes.getString("tableName");
    this.daoClass = attributes.getClass("batchDaoClass");
}
 
开发者ID:appstatus,项目名称:appstatus-spring-boot-starter,代码行数:10,代码来源:AppStatusBatchConfig.java

示例2: doProcessConfigurationClass

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
 * Apply processing and build a complete {@link ConfigurationClass} by reading the
 * annotations, members and methods from the source class. This method can be called
 * multiple times as relevant sources are discovered.
 * @param configClass the configuration class being build
 * @param sourceClass a source class
 * @return the superclass, {@code null} if none found or previously processed
 */
protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) throws IOException {
	// recursively process any member (nested) classes first
	processMemberClasses(configClass, sourceClass);

	// process any @PropertySource annotations
	for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable(
			sourceClass.getMetadata(), PropertySources.class, org.springframework.context.annotation.PropertySource.class)) {
		processPropertySource(propertySource);
	}

	// process any @ComponentScan annotations
	AnnotationAttributes componentScan = AnnotationConfigUtils.attributesFor(sourceClass.getMetadata(), ComponentScan.class);
	if (componentScan != null) {
		// the config class is annotated with @ComponentScan -> perform the scan immediately
		if (!this.conditionEvaluator.shouldSkip(sourceClass.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) {
			Set<BeanDefinitionHolder> scannedBeanDefinitions =
					this.componentScanParser.parse(componentScan, sourceClass.getMetadata().getClassName());

			// check the set of scanned definitions for any further config classes and parse recursively if necessary
			for (BeanDefinitionHolder holder : scannedBeanDefinitions) {
				if (ConfigurationClassUtils.checkConfigurationClassCandidate(holder.getBeanDefinition(), this.metadataReaderFactory)) {
					parse(holder.getBeanDefinition().getBeanClassName(), holder.getBeanName());
				}
			}
		}
	}

	// process any @Import annotations
	processImports(configClass, sourceClass, getImports(sourceClass), true);

	// process any @ImportResource annotations
	if (sourceClass.getMetadata().isAnnotated(ImportResource.class.getName())) {
		AnnotationAttributes importResource = AnnotationConfigUtils.attributesFor(sourceClass.getMetadata(), ImportResource.class);
		String[] resources = importResource.getStringArray("value");
		Class<? extends BeanDefinitionReader> readerClass = importResource.getClass("reader");
		for (String resource : resources) {
			String resolvedResource = this.environment.resolveRequiredPlaceholders(resource);
			configClass.addImportedResource(resolvedResource, readerClass);
		}
	}

	// process individual @Bean methods
	Set<MethodMetadata> beanMethods = sourceClass.getMetadata().getAnnotatedMethods(Bean.class.getName());
	for (MethodMetadata methodMetadata : beanMethods) {
		configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass));
	}

	// process superclass, if any
	if (sourceClass.getMetadata().hasSuperClass()) {
		String superclass = sourceClass.getMetadata().getSuperClassName();
		if (!superclass.startsWith("java") && !this.knownSuperclasses.containsKey(superclass)) {
			this.knownSuperclasses.put(superclass, configClass);
			// superclass found, return its annotation metadata and recurse
			try {
				return sourceClass.getSuperClass();
			}
			catch (ClassNotFoundException ex) {
				throw new IllegalStateException(ex);
			}
		}
	}

	// no superclass, processing is complete
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:74,代码来源:ConfigurationClassParser.java

示例3: findMyBatisBeanDefinitions

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
private Map<String, BeanDefinition> findMyBatisBeanDefinitions() {
    String[] enumsLocations = attributes.getStringArray(Constant.ENUMS_LOCATIONS_ATTRIBUTE_NAME);
    String[] basePackages = attributes.getStringArray(Constant.BASE_PACKAGES_ATTRIBUTE_NAME);
    AnnotationAttributes[] plugins = attributes.getAnnotationArray(Constant.PLUGINS_ATTRIBUTE_NAME);

    if (ArrayUtils.isEmpty(enumsLocations)) {
        enumsLocations = findDefaultPackage(metadata);
    }
    if (ArrayUtils.isEmpty(basePackages)) {
        basePackages = findDefaultPackage(metadata);
    }

    Map<String, BeanDefinition> beanDefinitions = new HashMap<>(16);

    BeanDefinitionBuilder sqlSessionFactoryBean = BeanDefinitionBuilder.genericBeanDefinition(SqlSessionFactoryBean.class);

    if (useFlyway) {
        sqlSessionFactoryBean.addDependsOn(Constant.FLYWAY_BEAN_NAME);
    }

    sqlSessionFactoryBean.addPropertyReference("dataSource", Constant.DATA_SOURCE_BEAN_NAME);
    sqlSessionFactoryBean.addPropertyValue("mapperLocations", "classpath*:/META-INF/mybatis/**/*Mapper.xml");
    sqlSessionFactoryBean.addPropertyValue("configLocation", "classpath:/META-INF/mybatis/mybatis.xml");
    TypeHandlerScanner scanner = new TypeHandlerScanner();
    sqlSessionFactoryBean.addPropertyValue("typeHandlers", scanner.find(StringUtils.join(enumsLocations, ",")));
    List<Interceptor> pluginsList = new ArrayList<>(plugins.length);
    List<Class<? extends Interceptor>> clazz = new ArrayList<>(plugins.length);
    for (AnnotationAttributes plugin : plugins) {
        Class<? extends Interceptor> pluginClass = plugin.getClass("value");
        AnnotationAttributes[] params = plugin.getAnnotationArray("params");

        clazz.add(pluginClass);
        Interceptor interceptor = BeanUtils.instantiate(pluginClass);
        BeanWrapper beanWrapper = new BeanWrapperImpl(interceptor);
        for (AnnotationAttributes param : params) {
            String key = param.getString("key");
            String value = param.getString("value");

            PropertyDescriptor descriptor = beanWrapper.getPropertyDescriptor(key);
            Method writeMethod = descriptor.getWriteMethod();
            Method readMethod = descriptor.getReadMethod();
            writeMethod.setAccessible(true);
            try {
                Class<?> returnType = readMethod.getReturnType();
                Object valueObject = value;
                if (Integer.class.equals(returnType) || int.class.equals(returnType)) {
                    valueObject = Integer.valueOf(value);
                } else if (Long.class.equals(returnType) || long.class.equals(returnType)) {
                    valueObject = Long.valueOf(value);
                } else if (Boolean.class.equals(returnType) || boolean.class.equals(returnType)) {
                    valueObject = Boolean.valueOf(value);
                } else if (Double.class.equals(returnType) || double.class.equals(returnType)) {
                    valueObject = Double.valueOf(value);
                }

                writeMethod.invoke(interceptor, valueObject);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        pluginsList.add(interceptor);
    }
    if (!clazz.contains(PaginationInterceptor.class)) {
        pluginsList.add(BeanUtils.instantiate(PaginationInterceptor.class));
    }

    sqlSessionFactoryBean.addPropertyValue("plugins", pluginsList);

    BeanDefinitionBuilder scannerConfigurerBean = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
    scannerConfigurerBean.addPropertyValue("basePackage", StringUtils.join(basePackages, ","));
    scannerConfigurerBean.addPropertyValue("annotationClass", Repository.class);
    scannerConfigurerBean.addPropertyValue("sqlSessionFactoryBeanName", "sqlSessionFactory");

    beanDefinitions.put("sqlSessionFactory", sqlSessionFactoryBean.getBeanDefinition());
    beanDefinitions.put("mapperScannerConfigurer", scannerConfigurerBean.getBeanDefinition());

    return beanDefinitions;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:80,代码来源:MyBatisConfigurationBuilder.java

示例4: doProcessConfigurationClass

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
 * Apply processing and build a complete {@link ConfigurationClass} by reading the
 * annotations, members and methods from the source class. This method can be called
 * multiple times as relevant sources are discovered.
 * @param configClass the configuration class being build
 * @param sourceClass a source class
 * @return the superclass, or {@code null} if none found or previously processed
 */
protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) throws IOException {
	// Recursively process any member (nested) classes first
	processMemberClasses(configClass, sourceClass);

	// Process any @PropertySource annotations
	for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable(
			sourceClass.getMetadata(), PropertySources.class, org.springframework.context.annotation.PropertySource.class)) {
		if (this.environment instanceof ConfigurableEnvironment) {
			processPropertySource(propertySource);
		}
		else {
			logger.warn("Ignoring @PropertySource annotation on [" + sourceClass.getMetadata().getClassName() +
					"]. Reason: Environment must implement ConfigurableEnvironment");
		}
	}

	// Process any @ComponentScan annotations
	Set<AnnotationAttributes> componentScans = AnnotationConfigUtils.attributesForRepeatable(
			sourceClass.getMetadata(), ComponentScans.class, ComponentScan.class);
	if (!componentScans.isEmpty() && !this.conditionEvaluator.shouldSkip(sourceClass.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) {
		for (AnnotationAttributes componentScan : componentScans) {
			// The config class is annotated with @ComponentScan -> perform the scan immediately
			Set<BeanDefinitionHolder> scannedBeanDefinitions =
					this.componentScanParser.parse(componentScan, sourceClass.getMetadata().getClassName());
			// Check the set of scanned definitions for any further config classes and parse recursively if necessary
			for (BeanDefinitionHolder holder : scannedBeanDefinitions) {
				if (ConfigurationClassUtils.checkConfigurationClassCandidate(holder.getBeanDefinition(), this.metadataReaderFactory)) {
					parse(holder.getBeanDefinition().getBeanClassName(), holder.getBeanName());
				}
			}
		}
	}

	// Process any @Import annotations
	processImports(configClass, sourceClass, getImports(sourceClass), true);

	// Process any @ImportResource annotations
	if (sourceClass.getMetadata().isAnnotated(ImportResource.class.getName())) {
		AnnotationAttributes importResource = AnnotationConfigUtils.attributesFor(sourceClass.getMetadata(), ImportResource.class);
		String[] resources = importResource.getAliasedStringArray("locations", ImportResource.class, sourceClass);
		Class<? extends BeanDefinitionReader> readerClass = importResource.getClass("reader");
		for (String resource : resources) {
			String resolvedResource = this.environment.resolveRequiredPlaceholders(resource);
			configClass.addImportedResource(resolvedResource, readerClass);
		}
	}

	// Process individual @Bean methods
	Set<MethodMetadata> beanMethods = sourceClass.getMetadata().getAnnotatedMethods(Bean.class.getName());
	for (MethodMetadata methodMetadata : beanMethods) {
		configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass));
	}

	// Process default methods on interfaces
	processInterfaces(configClass, sourceClass);

	// Process superclass, if any
	if (sourceClass.getMetadata().hasSuperClass()) {
		String superclass = sourceClass.getMetadata().getSuperClassName();
		if (!superclass.startsWith("java") && !this.knownSuperclasses.containsKey(superclass)) {
			this.knownSuperclasses.put(superclass, configClass);
			// Superclass found, return its annotation metadata and recurse
			return sourceClass.getSuperClass();
		}
	}

	// No superclass -> processing is complete
	return null;
}
 
开发者ID:txazo,项目名称:spring,代码行数:78,代码来源:ConfigurationClassParser.java

示例5: ContextConfigurationAttributes

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
 * Construct a new {@link ContextConfigurationAttributes} instance for the
 * supplied {@link AnnotationAttributes} (parsed from a
 * {@link ContextConfiguration @ContextConfiguration} annotation) and
 * the {@linkplain Class test class} that declared them.
 * @param declaringClass the test class that declared {@code @ContextConfiguration}
 * @param annAttrs the annotation attributes from which to retrieve the attributes
 */
@SuppressWarnings("unchecked")
public ContextConfigurationAttributes(Class<?> declaringClass, AnnotationAttributes annAttrs) {
	this(declaringClass, annAttrs.getStringArray("locations"), annAttrs.getClassArray("classes"), annAttrs.getBoolean("inheritLocations"),
		(Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[]) annAttrs.getClassArray("initializers"),
		annAttrs.getBoolean("inheritInitializers"), annAttrs.getString("name"), (Class<? extends ContextLoader>) annAttrs.getClass("loader"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:ContextConfigurationAttributes.java


注:本文中的org.springframework.core.annotation.AnnotationAttributes.getClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。