本文整理汇总了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 ...
};
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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");
}
}));
}
示例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);
}
}
}
}
示例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);
}
示例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];
}
示例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()]);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}