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


Java AnnotationMetadata.getAnnotationTypes方法代码示例

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


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

示例1: determineBeanNameFromAnnotation

import org.springframework.core.type.AnnotationMetadata; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:AnnotationBeanNameGenerator.java

示例2: registerBeanDefinitions

import org.springframework.core.type.AnnotationMetadata; //导入方法依赖的package包/类
/**
 * Register, escalate, and configure the standard auto proxy creator (APC) against the
 * given registry. Works by finding the nearest annotation declared on the importing
 * {@code @Configuration} class that has both {@code mode} and {@code proxyTargetClass}
 * attributes. If {@code mode} is set to {@code PROXY}, the APC is registered; if
 * {@code proxyTargetClass} is set to {@code true}, then the APC is forced to use
 * subclass (CGLIB) proxying.
 * <p>Several {@code @Enable*} annotations expose both {@code mode} and
 * {@code proxyTargetClass} attributes. It is important to note that most of these
 * capabilities end up sharing a {@linkplain AopConfigUtils#AUTO_PROXY_CREATOR_BEAN_NAME
 * single APC}. For this reason, this implementation doesn't "care" exactly which
 * annotation it finds -- as long as it exposes the right {@code mode} and
 * {@code proxyTargetClass} attributes, the APC can be registered and configured all
 * the same.
 */
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
	boolean candidateFound = false;
	Set<String> annoTypes = importingClassMetadata.getAnnotationTypes();
	for (String annoType : annoTypes) {
		AnnotationAttributes candidate = AnnotationConfigUtils.attributesFor(importingClassMetadata, annoType);
		Object mode = candidate.get("mode");
		Object proxyTargetClass = candidate.get("proxyTargetClass");
		if (mode != null && proxyTargetClass != null && mode.getClass().equals(AdviceMode.class) &&
				proxyTargetClass.getClass().equals(Boolean.class)) {
			candidateFound = true;
			if (mode == AdviceMode.PROXY) {
				AopConfigUtils.registerAutoProxyCreatorIfNecessary(registry);
				if ((Boolean) proxyTargetClass) {
					AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
					return;
				}
			}
		}
	}
	if (!candidateFound) {
		String name = getClass().getSimpleName();
		logger.warn(String.format("%s was imported but no annotations were found " +
				"having both 'mode' and 'proxyTargetClass' attributes of type " +
				"AdviceMode and boolean respectively. This means that auto proxy " +
				"creator registration and configuration may not have occured as " +
				"intended, and components may not be proxied as expected. Check to " +
				"ensure that %s has been @Import'ed on the same class where these " +
				"annotations are declared; otherwise remove the import of %s " +
				"altogether.", name, name, name));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:48,代码来源:AutoProxyRegistrar.java

示例3: determineBeanNameFromAnnotation

import org.springframework.core.type.AnnotationMetadata; //导入方法依赖的package包/类
@Override
protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) {
	AnnotationMetadata amd = annotatedDef.getMetadata();
	Set<String> types = amd.getAnnotationTypes();
	String beanName = null;
	for (String type : types) {
		Map<String, Object> attributes = amd.getAnnotationAttributes(type);
		if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) {
			String value = null;
			if (PermissionForRight.class.getName().equals(type)) {
				Right right = (Right)attributes.get("value");
				value = "permission" + right.name();
			} else if (GwtRpcImplements.class.getName().equals(type)) {
				Class<?> requestClass = (Class<?>)attributes.get("value");
				value = requestClass.getName();
			} else if (GwtRpcLogging.class.getName().equals(type)) {
				continue;
			} else {
				value = (String) attributes.get("value");
			}
			if (StringUtils.hasLength(value)) {
				if (beanName != null && !value.equals(beanName)) {
					throw new IllegalStateException("Stereotype annotations suggest inconsistent " +
							"component names: '" + beanName + "' versus '" + value + "'");
				}
				beanName = value;
			}
		}
	}
	return beanName;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:32,代码来源:CustomBeanNameGenerator.java


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