當前位置: 首頁>>代碼示例>>Java>>正文


Java AnnotationAttributes類代碼示例

本文整理匯總了Java中org.springframework.core.annotation.AnnotationAttributes的典型用法代碼示例。如果您正苦於以下問題:Java AnnotationAttributes類的具體用法?Java AnnotationAttributes怎麽用?Java AnnotationAttributes使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AnnotationAttributes類屬於org.springframework.core.annotation包,在下文中一共展示了AnnotationAttributes類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: selectImports

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
/**
 * 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 ...
    };

}
 
開發者ID:jaschenk,項目名稱:Your-Microservice,代碼行數:27,代碼來源:YourMicroserviceBeanConfiguration.java

示例2: buildPostProcessorDefinition

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
private BeanDefinition buildPostProcessorDefinition(AnnotationMetadata importMetadata, AnnotationAttributes attributes) {
  SnowdropRepositoryConfigExtension extension = new SnowdropRepositoryConfigExtension();
  BeanDefinitionBuilder builder = BeanDefinitionBuilder
          .rootBeanDefinition(JpaRepositoryFactoryBeanSnowdropPostProcessor.class);

  builder.getRawBeanDefinition().setSource(importMetadata);

  builder.addPropertyValue("queryLookupStrategyKey", attributes.get(QUERY_LOOKUP_STRATEGY));

  NamedQueriesBeanDefinitionBuilder definitionBuilder = new NamedQueriesBeanDefinitionBuilder(
          extension.getDefaultNamedQueryLocation());

  String namedQueriesLocation = attributes.getString(NAMED_QUERIES_LOCATION);
  if (StringUtils.hasText(namedQueriesLocation)) {
    definitionBuilder.setLocations(namedQueriesLocation);
  }
  builder.addPropertyValue("namedQueriesLocation", definitionBuilder.build(importMetadata));

  return builder.getBeanDefinition();
}
 
開發者ID:snowdrop,項目名稱:spring-data-snowdrop,代碼行數:21,代碼來源:JpaWithSnowdropRegistrar.java

示例3: resolveScopeMetadata

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
@Override
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
	ScopeMetadata metadata = new ScopeMetadata();
	if (definition instanceof AnnotatedBeanDefinition) {
		AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
		AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(annDef.getMetadata(), this.scopeAnnotationType);
		if (attributes != null) {
			metadata.setScopeName(attributes.getString("value"));
			ScopedProxyMode proxyMode = attributes.getEnum("proxyMode");
			if (proxyMode == null || proxyMode == ScopedProxyMode.DEFAULT) {
				proxyMode = this.defaultProxyMode;
			}
			metadata.setScopedProxyMode(proxyMode);
		}
	}
	return metadata;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:AnnotationScopeMetadataResolver.java

示例4: determineBeanNameFromAnnotation

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的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

示例5: registerBeanDefinitions

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
@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);
	}
}
 
開發者ID:melthaw,項目名稱:spring-backend-boilerplate,代碼行數:20,代碼來源:EnableMenuImportSelector.java

示例6: toMetadata

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
private Map<String,Object> toMetadata(AnnotationAttributes[] metadatas) {
	if (metadatas == null) {
		return new HashMap<>();
	}

	return Stream.of(metadatas).collect(Collectors.toMap(item -> item.getString("key"), item -> {
		Metadata.ValueType valueType = item.getEnum("type");
		switch (valueType) {
			case Boolean:
				return item.getBoolean("value");
			case Short:
			case Integer:
			case Long:
				return item.getNumber("value");
			case BigDecimal:
				return new BigDecimal(item.getString("value"));
			default:
				return item.getString("value");
		}
	}));
}
 
開發者ID:melthaw,項目名稱:spring-backend-boilerplate,代碼行數:22,代碼來源:EnableMenuImportSelector.java

示例7: registerBeanDefinitions

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
@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);
			}
		}
	}
}
 
開發者ID:holon-platform,項目名稱:holon-core,代碼行數:18,代碼來源:AbstractRepeatableAnnotationRegistrar.java

示例8: registerBeanDefinitions

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
@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);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:18,代碼來源:ApolloConfigRegistrar.java

示例9: selectImports

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableCache.class.getName(), false));
    Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", EnableCache.class.getName(), importingClassMetadata.getClassName()));

    CacheMode cacheMode = attributes.getEnum(CACHE_MODE_ATTRIBUTE_NAME);

    if (cacheMode == CacheMode.EHCAHE) {
        return new String[]{EhcacheCacheConfiguration.class.getName()};
    } else if (cacheMode == CacheMode.GUAVA) {
        return new String[]{GuavaCacheConfiguration.class.getName()};
    } else if (cacheMode == CacheMode.REDIS) {
        return new String[]{RedisCacheConfiguration.class.getName()};
    } else if (cacheMode == CacheMode.MEMCACHED) {
        return new String[]{MemcachedCacheConfiguration.class.getName()};
    } else if (cacheMode == CacheMode.OSCACHE) {
        return new String[]{OscacheCacheConfiguration.class.getName()};
    }

    return new String[0];
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:22,代碼來源:CacheImportSelector.java

示例10: selectImports

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableSearch.class.getName(), false));
    Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", EnableSearch.class.getName(), importingClassMetadata.getClassName()));

    List<String> imports = new ArrayList<>();

    SearchType searchType = attributes.getEnum(SEARCH_TYPE_ATTRIBUTE_NAME);
    if (SearchType.SOLR.equals(searchType)) {
        imports.add(SolrConfiguration.class.getName());
    } else if (SearchType.LUCENE.equals(searchType)) {
        imports.add(LuceneConfiguration.class.getName());
    }

    return imports.toArray(new String[imports.size()]);
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:17,代碼來源:SearchConfigurationSelector.java

示例11: getPackagesToScan

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
	AnnotationAttributes attributes = AnnotationAttributes
			.fromMap(metadata.getAnnotationAttributes(EntityScan.class.getName()));
	String[] basePackages = attributes.getAliasedStringArray("basePackages",
			EntityScan.class, metadata.getClassName());
	Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
	Set<String> packagesToScan = new LinkedHashSet<String>();
	packagesToScan.addAll(Arrays.asList(basePackages));
	for (Class<?> basePackageClass : basePackageClasses) {
		packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
	}
	if (packagesToScan.isEmpty()) {
		return Collections
				.singleton(ClassUtils.getPackageName(metadata.getClassName()));
	}
	return packagesToScan;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:EntityScanRegistrar.java

示例12: registerBeanDefinitions

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableMongo.class.getName(), false));
    Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", EnableMongo.class.getName(), metadata.getClassName()));

    String[] domainPackage = attributes.getStringArray(DOMAIN_PACKAGES_ATTRIBUTE_NAME);
    if (ArrayUtils.isEmpty(domainPackage)) {
        domainPackage = findDefaultPackage(metadata);
    }

    String[] basePackages = attributes.getStringArray(BASE_PACKAGES_ATTRIBUTE_NAME);
    if (ArrayUtils.isEmpty(basePackages)) {
        domainPackage = findDefaultPackage(metadata);
    }

    initMongoDataSource(attributes);
    initMongoMappingContext(domainPackage);
    initMappingContextIsNewStrategyFactory();
    initMappingConverter();
    initMongoPersistentEntityIndexCreator();
    initMongoTemplate();
    initMongoRepositoryFactory();
    initMongoRepository(metadata, registry);

    BeanRegisterUtils.registerBeans(BEAN_DEFINITION_MAP, registry);
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:27,代碼來源:MongoBeanDefinitionRegistrar.java

示例13: resolveScopeMetadata

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
@Override
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
	ScopeMetadata metadata = new ScopeMetadata();
	if (definition instanceof AnnotatedBeanDefinition) {
		AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
		AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(annDef.getMetadata(), this.scopeAnnotationType);
		if (attributes != null) {
			metadata.setScopeName(attributes.getAliasedString("value", this.scopeAnnotationType, definition.getSource()));
			ScopedProxyMode proxyMode = attributes.getEnum("proxyMode");
			if (proxyMode == null || proxyMode == ScopedProxyMode.DEFAULT) {
				proxyMode = this.defaultProxyMode;
			}
			metadata.setScopedProxyMode(proxyMode);
		}
	}
	return metadata;
}
 
開發者ID:txazo,項目名稱:spring,代碼行數:18,代碼來源:AnnotationScopeMetadataResolver.java

示例14: selectImports

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
/**
 * This implementation resolves the type of annotation from generic metadata and
 * validates that (a) the annotation is in fact present on the importing
 * {@code @Configuration} class and (b) that the given annotation has an
 * {@linkplain #getAdviceModeAttributeName() advice mode attribute} of type
 * {@link AdviceMode}.
 * <p>The {@link #selectImports(AdviceMode)} method is then invoked, allowing the
 * concrete implementation to choose imports in a safe and convenient fashion.
 * @throws IllegalArgumentException if expected annotation {@code A} is not present
 * on the importing {@code @Configuration} class or if {@link #selectImports(AdviceMode)}
 * returns {@code null}
 */
@Override
public final String[] selectImports(AnnotationMetadata importingClassMetadata) {
	Class<?> annoType = GenericTypeResolver.resolveTypeArgument(getClass(), AdviceModeImportSelector.class);
	AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(importingClassMetadata, annoType);
	if (attributes == null) {
		throw new IllegalArgumentException(String.format(
			"@%s is not present on importing class '%s' as expected",
			annoType.getSimpleName(), importingClassMetadata.getClassName()));
	}

	AdviceMode adviceMode = attributes.getEnum(this.getAdviceModeAttributeName());
	String[] imports = selectImports(adviceMode);
	if (imports == null) {
		throw new IllegalArgumentException(String.format("Unknown AdviceMode: '%s'", adviceMode));
	}
	return imports;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:30,代碼來源:AdviceModeImportSelector.java

示例15: selectImports

import org.springframework.core.annotation.AnnotationAttributes; //導入依賴的package包/類
@Override
public String[] selectImports(AnnotationMetadata metadata) {
	if (!isEnabled(metadata)) {
		return NO_IMPORTS;
	}
	try {
		AnnotationAttributes attributes = getAttributes(metadata);
		List<String> configurations = getCandidateConfigurations(metadata,
				attributes);
		configurations = removeDuplicates(configurations);
		Set<String> exclusions = getExclusions(metadata, attributes);
		configurations.removeAll(exclusions);
		configurations = sort(configurations);
		recordWithConditionEvaluationReport(configurations, exclusions);
		return configurations.toArray(new String[configurations.size()]);
	}
	catch (IOException ex) {
		throw new IllegalStateException(ex);
	}
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:21,代碼來源:EnableAutoConfigurationImportSelector.java


注:本文中的org.springframework.core.annotation.AnnotationAttributes類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。