use of org.springframework.core.annotation.AnnotationAttributes in project spring-boot by spring-projects.
the class SpringBootApplicationTests method nameGeneratorDefaultToBeanNameGenerator.
@Test
void nameGeneratorDefaultToBeanNameGenerator() {
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(DefaultSpringBootApplication.class, ComponentScan.class);
assertThat(attributes.get("nameGenerator")).isEqualTo(BeanNameGenerator.class);
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-framework by spring-projects.
the class MergedSqlConfig method mergeAttributes.
private AnnotationAttributes mergeAttributes(SqlConfig localSqlConfig, Class<?> testClass) {
AnnotationAttributes localAttributes = AnnotationUtils.getAnnotationAttributes(localSqlConfig, false, false);
// Enforce comment prefix aliases within the local @SqlConfig.
enforceCommentPrefixAliases(localAttributes);
// Get global attributes, if any.
SqlConfig globalSqlConfig = TestContextAnnotationUtils.findMergedAnnotation(testClass, SqlConfig.class);
// Use local attributes only?
if (globalSqlConfig == null) {
return localAttributes;
}
AnnotationAttributes globalAttributes = AnnotationUtils.getAnnotationAttributes(globalSqlConfig, false, false);
// Enforce comment prefix aliases within the global @SqlConfig.
enforceCommentPrefixAliases(globalAttributes);
for (String key : globalAttributes.keySet()) {
Object value = localAttributes.get(key);
if (isExplicitValue(value)) {
// Override global attribute with local attribute.
globalAttributes.put(key, value);
// Ensure comment prefix aliases are honored during the merge.
if (key.equals(COMMENT_PREFIX) && isEmptyArray(localAttributes.get(COMMENT_PREFIXES))) {
globalAttributes.put(COMMENT_PREFIXES, value);
} else if (key.equals(COMMENT_PREFIXES) && isEmptyString(localAttributes.get(COMMENT_PREFIX))) {
globalAttributes.put(COMMENT_PREFIX, value);
}
}
}
return globalAttributes;
}
use of org.springframework.core.annotation.AnnotationAttributes in project dubbo by alibaba.
the class DubboConfigConfigurationRegistrar method registerBeanDefinitions.
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableDubboConfig.class.getName()));
boolean multiple = attributes.getBoolean("multiple");
// Single Config Bindings
registerBeans(registry, DubboConfigConfiguration.Single.class);
if (multiple) {
// Since 2.6.6 https://github.com/apache/dubbo/issues/3193
registerBeans(registry, DubboConfigConfiguration.Multiple.class);
}
// Since 2.7.6
registerCommonBeans(registry);
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-framework by spring-projects.
the class ComponentScanAnnotationParser method parse.
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, String declaringClass) {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(this.registry, componentScan.getBoolean("useDefaultFilters"), this.environment, this.resourceLoader);
Class<? extends BeanNameGenerator> generatorClass = componentScan.getClass("nameGenerator");
boolean useInheritedGenerator = (BeanNameGenerator.class == generatorClass);
scanner.setBeanNameGenerator(useInheritedGenerator ? this.beanNameGenerator : BeanUtils.instantiateClass(generatorClass));
ScopedProxyMode scopedProxyMode = componentScan.getEnum("scopedProxy");
if (scopedProxyMode != ScopedProxyMode.DEFAULT) {
scanner.setScopedProxyMode(scopedProxyMode);
} else {
Class<? extends ScopeMetadataResolver> resolverClass = componentScan.getClass("scopeResolver");
scanner.setScopeMetadataResolver(BeanUtils.instantiateClass(resolverClass));
}
scanner.setResourcePattern(componentScan.getString("resourcePattern"));
for (AnnotationAttributes includeFilterAttributes : componentScan.getAnnotationArray("includeFilters")) {
List<TypeFilter> typeFilters = TypeFilterUtils.createTypeFiltersFor(includeFilterAttributes, this.environment, this.resourceLoader, this.registry);
for (TypeFilter typeFilter : typeFilters) {
scanner.addIncludeFilter(typeFilter);
}
}
for (AnnotationAttributes excludeFilterAttributes : componentScan.getAnnotationArray("excludeFilters")) {
List<TypeFilter> typeFilters = TypeFilterUtils.createTypeFiltersFor(excludeFilterAttributes, this.environment, this.resourceLoader, this.registry);
for (TypeFilter typeFilter : typeFilters) {
scanner.addExcludeFilter(typeFilter);
}
}
boolean lazyInit = componentScan.getBoolean("lazyInit");
if (lazyInit) {
scanner.getBeanDefinitionDefaults().setLazyInit(true);
}
Set<String> basePackages = new LinkedHashSet<>();
String[] basePackagesArray = componentScan.getStringArray("basePackages");
for (String pkg : basePackagesArray) {
String[] tokenized = StringUtils.tokenizeToStringArray(this.environment.resolvePlaceholders(pkg), ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
Collections.addAll(basePackages, tokenized);
}
for (Class<?> clazz : componentScan.getClassArray("basePackageClasses")) {
basePackages.add(ClassUtils.getPackageName(clazz));
}
if (basePackages.isEmpty()) {
basePackages.add(ClassUtils.getPackageName(declaringClass));
}
scanner.addExcludeFilter(new AbstractTypeHierarchyTraversingFilter(false, false) {
@Override
protected boolean matchClassName(String className) {
return declaringClass.equals(className);
}
});
return scanner.doScan(StringUtils.toStringArray(basePackages));
}
use of org.springframework.core.annotation.AnnotationAttributes in project spring-framework by spring-projects.
the class BeanAnnotationHelper method determineBeanNameFor.
public static String determineBeanNameFor(Method beanMethod) {
String beanName = beanNameCache.get(beanMethod);
if (beanName == null) {
// By default, the bean name is the name of the @Bean-annotated method
beanName = beanMethod.getName();
// Check to see if the user has explicitly set a custom bean name...
AnnotationAttributes bean = AnnotatedElementUtils.findMergedAnnotationAttributes(beanMethod, Bean.class, false, false);
if (bean != null) {
String[] names = bean.getStringArray("name");
if (names.length > 0) {
beanName = names[0];
}
}
beanNameCache.put(beanMethod, beanName);
}
return beanName;
}
Aggregations