use of org.springframework.core.type.AnnotationMetadata in project spring-framework by spring-projects.
the class ImportAwareTests method metadataFromImportsTwoThenOne.
@Test
public void metadataFromImportsTwoThenOne() {
AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(ConfigurationTwo.class, ConfigurationOne.class).getBean(MetadataHolder.class).importMetadata;
assertEquals(ConfigurationOne.class, ((StandardAnnotationMetadata) importMetadata).getIntrospectedClass());
}
use of org.springframework.core.type.AnnotationMetadata in project spring-framework by spring-projects.
the class ImportAwareTests method indirectlyAnnotatedWithImport.
@Test
public void indirectlyAnnotatedWithImport() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(IndirectlyImportingConfig.class);
ctx.refresh();
assertNotNull(ctx.getBean("importedConfigBean"));
ImportedConfig importAwareConfig = ctx.getBean(ImportedConfig.class);
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
assertThat("import metadata was not injected", importMetadata, notNullValue());
assertThat(importMetadata.getClassName(), is(IndirectlyImportingConfig.class.getName()));
AnnotationAttributes enableAttribs = AnnotationConfigUtils.attributesFor(importMetadata, EnableImportedConfig.class);
String foo = enableAttribs.getString("foo");
assertThat(foo, is("xyz"));
}
use of org.springframework.core.type.AnnotationMetadata in project spring-framework by spring-projects.
the class ImportAwareTests method metadataFromImportsOneThenTwo.
@Test
public void metadataFromImportsOneThenTwo() {
AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(ConfigurationOne.class, ConfigurationTwo.class).getBean(MetadataHolder.class).importMetadata;
assertEquals(ConfigurationOne.class, ((StandardAnnotationMetadata) importMetadata).getIntrospectedClass());
}
use of org.springframework.core.type.AnnotationMetadata in project leopard by tanhaichao.
the class OptionScanner method getValue.
protected String getValue(BeanDefinition beanDefinition) {
AnnotationMetadata metadata = ((AnnotatedBeanDefinition) beanDefinition).getMetadata();
AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(Option.class.getName(), false));
return attributes.getString("value");
}
use of org.springframework.core.type.AnnotationMetadata in project spring-framework by spring-projects.
the class ConfigurationClassParser method retrieveBeanMethodMetadata.
/**
* Retrieve the metadata for all <code>@Bean</code> methods.
*/
private Set<MethodMetadata> retrieveBeanMethodMetadata(SourceClass sourceClass) {
AnnotationMetadata original = sourceClass.getMetadata();
Set<MethodMetadata> beanMethods = original.getAnnotatedMethods(Bean.class.getName());
if (beanMethods.size() > 1 && original instanceof StandardAnnotationMetadata) {
// order, even between different runs of the same application on the same JVM.
try {
AnnotationMetadata asm = this.metadataReaderFactory.getMetadataReader(original.getClassName()).getAnnotationMetadata();
Set<MethodMetadata> asmMethods = asm.getAnnotatedMethods(Bean.class.getName());
if (asmMethods.size() >= beanMethods.size()) {
Set<MethodMetadata> selectedMethods = new LinkedHashSet<>(asmMethods.size());
for (MethodMetadata asmMethod : asmMethods) {
for (MethodMetadata beanMethod : beanMethods) {
if (beanMethod.getMethodName().equals(asmMethod.getMethodName())) {
selectedMethods.add(beanMethod);
break;
}
}
}
if (selectedMethods.size() == beanMethods.size()) {
// All reflection-detected methods found in ASM method set -> proceed
beanMethods = selectedMethods;
}
}
} catch (IOException ex) {
logger.debug("Failed to read class file via ASM for determining @Bean method order", ex);
// No worries, let's continue with the reflection metadata we started with...
}
}
return beanMethods;
}
Aggregations