org.springframework.core.type.StandardAnnotationMetadata Java Examples

The following examples show how to use org.springframework.core.type.StandardAnnotationMetadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionalServiceStandardAnnotationMetadataBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {

        // 读取 @TransactionService AnnotationMetadata 信息
        AnnotationMetadata annotationMetadata = new StandardAnnotationMetadata(TransactionalServiceStandardAnnotationMetadataBootstrap.class);

        // 获取所有的元注解类型(全类名)集合
        Set<String> metaAnnotationTypes = annotationMetadata.getAnnotationTypes()
                .stream() // TO Stream
                .map(annotationMetadata::getMetaAnnotationTypes) // 读取单注解的元注解类型集合
                .collect(LinkedHashSet::new, Set::addAll, Set::addAll); // 合并元注解类型(全类名)集合

        metaAnnotationTypes.forEach(metaAnnotation -> { // 读取所有元注解类型
            // 读取元注解属性信息
            Map<String, Object> annotationAttributes = annotationMetadata.getAnnotationAttributes(metaAnnotation);
            if (!CollectionUtils.isEmpty(annotationAttributes)) {
                annotationAttributes.forEach((name, value) ->
                        System.out.printf("注解 @%s 属性 %s = %s\n", ClassUtils.getShortName(metaAnnotation), name, value));
            }
        });
    }
 
Example #2
Source File: JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoScopedClass() {
	GenericApplicationContext acx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(acx);

	acx.registerBeanDefinition("noScopedClass", new AnnotatedGenericBeanDefinition(
		new StandardAnnotationMetadata(NoScopedClass.class)));
	acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(
		ScopedBeansConfiguration.class));
	acx.addBeanFactoryPostProcessor(JsfScopeAnnotationsAutoConfiguration.jsfScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.addBeanFactoryPostProcessor(CdiScopeAnnotationsAutoConfiguration.cdiScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.refresh();

	assertThat(acx.getBeanDefinition("noScopedClass").getScope())
		.isEqualTo("");
	assertThat(acx.getBeanDefinition("noScopedBean").getScope())
		.isEqualTo("");

}
 
Example #3
Source File: JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
@Test
public void testSessionScopedClass() {
	GenericApplicationContext acx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(acx);

	acx.registerBeanDefinition("sessionScopedClass", new AnnotatedGenericBeanDefinition(
		new StandardAnnotationMetadata(SessionScopedClass.class)));
	acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(
		ScopedBeansConfiguration.class));
	acx.addBeanFactoryPostProcessor(JsfScopeAnnotationsAutoConfiguration.jsfScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.addBeanFactoryPostProcessor(CdiScopeAnnotationsAutoConfiguration.cdiScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.refresh();

	assertThat(acx.getBeanDefinition("sessionScopedClass").getScope())
		.isEqualTo(WebApplicationContext.SCOPE_SESSION);
	assertThat(acx.getBeanDefinition("sessionScopedBean").getScope())
		.isEqualTo(WebApplicationContext.SCOPE_SESSION);
}
 
Example #4
Source File: JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
@Test
public void testViewScopedClass() {
	GenericApplicationContext acx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(acx);

	acx.registerBeanDefinition("viewScopedClass", new AnnotatedGenericBeanDefinition(
		new StandardAnnotationMetadata(ViewScopedClass.class)));
	acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(
		ScopedBeansConfiguration.class));
	acx.addBeanFactoryPostProcessor(JsfScopeAnnotationsAutoConfiguration.jsfScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.addBeanFactoryPostProcessor(CdiScopeAnnotationsAutoConfiguration.cdiScopeAnnotationsConfigurer(acx.getEnvironment()));
	acx.refresh();

	assertThat(acx.getBeanDefinition("viewScopedClass").getScope())
		.isEqualTo(ViewScope.SCOPE_VIEW);
	assertThat(acx.getBeanDefinition("viewScopedBean").getScope())
		.isEqualTo(ViewScope.SCOPE_VIEW);
}
 
Example #5
Source File: AbstractFunctionExecutionAutoConfigurationExtension.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
@Override
protected AbstractFunctionExecutionConfigurationSource newAnnotationBasedFunctionExecutionConfigurationSource(
		AnnotationMetadata annotationMetadata) {

	StandardAnnotationMetadata metadata =
		new StandardAnnotationMetadata(getConfiguration(), true);

	return new AnnotationFunctionExecutionConfigurationSource(metadata) {

		@Override
		public Iterable<String> getBasePackages() {
			return AutoConfigurationPackages.get(getBeanFactory());
		}
	};
}
 
Example #6
Source File: ConfigurationClassParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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) {
		// Try reading the class file via ASM for deterministic declaration order...
		// Unfortunately, the JVM's standard reflection returns methods in arbitrary
		// 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<MethodMetadata>(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;
}
 
Example #7
Source File: ConfigurationBeanFactoryPostProcessor.java    From conf4j with MIT License 5 votes vote down vote up
private boolean isConfigurationType(Class<?> configurationType) {
    if (configurationModelProvider != null) {
        return configurationModelProvider.isConfigurationType(configurationType);
    } else {
        // fallback to the simplified logic
        StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(configurationType);
        return metadata.isAbstract() && metadata.isIndependent() &&
                configurationAnnotations.stream().anyMatch(a -> findAnnotation(configurationType, a) != null);
    }
}
 
Example #8
Source File: ConfigurationClassParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Factory method to obtain a {@link SourceClass} from a {@link ConfigurationClass}.
 */
private SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException {
	AnnotationMetadata metadata = configurationClass.getMetadata();
	if (metadata instanceof StandardAnnotationMetadata) {
		return asSourceClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
	}
	return asSourceClass(metadata.getClassName());
}
 
Example #9
Source File: ConfigurationClassParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SourceClass(Object source) {
	this.source = source;
	if (source instanceof Class) {
		this.metadata = new StandardAnnotationMetadata((Class<?>) source, true);
	}
	else {
		this.metadata = ((MetadataReader) source).getAnnotationMetadata();
	}
}
 
Example #10
Source File: ConfigurationClass.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@link ConfigurationClass} with the given name.
 * @param clazz the underlying {@link Class} to represent
 * @param beanName name of the {@code @Configuration} class bean
 * @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
 */
public ConfigurationClass(Class<?> clazz, String beanName) {
	Assert.hasText(beanName, "Bean name must not be null");
	this.metadata = new StandardAnnotationMetadata(clazz, true);
	this.resource = new DescriptiveResource(clazz.getName());
	this.beanName = beanName;
}
 
Example #11
Source File: AnnotatedGenericBeanDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
 * allowing for ASM-based processing and avoidance of early loading of the bean class.
 * Note that this constructor is functionally equivalent to
 * {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
 * ScannedGenericBeanDefinition}, however the semantics of the latter indicate that a
 * bean was discovered specifically via component-scanning as opposed to other means.
 * @param metadata the annotation metadata for the bean class in question
 * @since 3.1.1
 */
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
	Assert.notNull(metadata, "AnnotationMetadata must not be null");
	if (metadata instanceof StandardAnnotationMetadata) {
		setBeanClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
	}
	else {
		setBeanClassName(metadata.getClassName());
	}
	this.metadata = metadata;
}
 
Example #12
Source File: AnnotatedGenericBeanDefinition.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
 * allowing for ASM-based processing and avoidance of early loading of the bean class.
 * Note that this constructor is functionally equivalent to
 * {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
 * ScannedGenericBeanDefinition}, however the semantics of the latter indicate that a
 * bean was discovered specifically via component-scanning as opposed to other means.
 * @param metadata the annotation metadata for the bean class in question
 * @since 3.1.1
 */
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
	Assert.notNull(metadata, "AnnotationMetadata must not be null");
	if (metadata instanceof StandardAnnotationMetadata) {
		setBeanClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
	}
	else {
		setBeanClassName(metadata.getClassName());
	}
	this.metadata = metadata;
}
 
Example #13
Source File: ConfigurationClassParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Factory method to obtain a {@link SourceClass} from a {@link ConfigurationClass}.
 */
public SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException {
	AnnotationMetadata metadata = configurationClass.getMetadata();
	if (metadata instanceof StandardAnnotationMetadata) {
		return asSourceClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
	}
	return asSourceClass(configurationClass.getMetadata().getClassName());
}
 
Example #14
Source File: ConfigurationClassParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public SourceClass(Object source) {
	this.source = source;
	if (source instanceof Class<?>) {
		this.metadata = new StandardAnnotationMetadata((Class<?>) source, true);
	}
	else {
		this.metadata = ((MetadataReader) source).getAnnotationMetadata();
	}
}
 
Example #15
Source File: ConfigurationClass.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@link ConfigurationClass} with the given name.
 * @param clazz the underlying {@link Class} to represent
 * @param beanName name of the {@code @Configuration} class bean
 * @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
 */
public ConfigurationClass(Class<?> clazz, String beanName) {
	Assert.hasText(beanName, "Bean name must not be null");
	this.metadata = new StandardAnnotationMetadata(clazz, true);
	this.resource = new DescriptiveResource(clazz.toString());
	this.beanName = beanName;
}
 
Example #16
Source File: AnnotatedGenericBeanDefinition.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
 * allowing for ASM-based processing and avoidance of early loading of the bean class.
 * Note that this constructor is functionally equivalent to
 * {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
 * ScannedGenericBeanDefinition}, however the semantics of the latter indicate that a
 * bean was discovered specifically via component-scanning as opposed to other means.
 * @param metadata the annotation metadata for the bean class in question
 * @since 3.1.1
 */
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
	Assert.notNull(metadata, "AnnotationMetadata must not be null");
	if (metadata instanceof StandardAnnotationMetadata) {
		setBeanClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
	}
	else {
		setBeanClassName(metadata.getClassName());
	}
	this.metadata = metadata;
}
 
Example #17
Source File: ImportAwareTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void metadataFromImportsOneThenTwo() {
	AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
			ConfigurationOne.class, ConfigurationTwo.class)
			.getBean(MetadataHolder.class).importMetadata;
	assertEquals(ConfigurationOne.class,
			((StandardAnnotationMetadata) importMetadata).getIntrospectedClass());
}
 
Example #18
Source File: ImportAwareTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void metadataFromImportsTwoThenOne() {
	AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
			ConfigurationTwo.class, ConfigurationOne.class)
			.getBean(MetadataHolder.class).importMetadata;
	assertEquals(ConfigurationOne.class,
			((StandardAnnotationMetadata) importMetadata).getIntrospectedClass());
}
 
Example #19
Source File: OAuth2ResourceServerConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
public static boolean matches(ConditionContext context) {
	Class<AuthorizationServerEndpointsConfigurationBeanCondition> type = AuthorizationServerEndpointsConfigurationBeanCondition.class;
	Conditional conditional = AnnotationUtils.findAnnotation(type, Conditional.class);
	StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(type);
	for (Class<? extends Condition> conditionType : conditional.value()) {
		Condition condition = BeanUtils.instantiateClass(conditionType);
		if (condition.matches(context, metadata)) {
			return true;
		}
	}
	return false;
}
 
Example #20
Source File: MongoContentAutoConfigureRegistrar.java    From spring-content with Apache License 2.0 5 votes vote down vote up
@Override
protected void registerContentStoreBeanDefinitions(
		AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

	AnnotationMetadata metadata = new StandardAnnotationMetadata(
			EnableMongoContentAutoConfiguration.class);
	AnnotationAttributes attributes = new AnnotationAttributes(
			metadata.getAnnotationAttributes(this.getAnnotation().getName()));

	String[] basePackages = this.getBasePackages();

	Set<GenericBeanDefinition> definitions = StoreUtils.getStoreCandidates(this.getEnvironment(), this.getResourceLoader(), basePackages, multipleStoreImplementationsDetected(), getIdentifyingTypes());

	this.buildAndRegisterDefinitions(importingClassMetadata, registry, attributes, basePackages, definitions);
}
 
Example #21
Source File: AnnotatedGenericBeanDefinition.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
 * allowing for ASM-based processing and avoidance of early loading of the bean class.
 * Note that this constructor is functionally equivalent to
 * {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
 * ScannedGenericBeanDefinition}, however the semantics of the latter indicate that a
 * bean was discovered specifically via component-scanning as opposed to other means.
 * @param metadata the annotation metadata for the bean class in question
 * @since 3.1.1
 */
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
	Assert.notNull(metadata, "AnnotationMetadata must not be null");
	if (metadata instanceof StandardAnnotationMetadata) {
		setBeanClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
	}
	else {
		setBeanClassName(metadata.getClassName());
	}
	this.metadata = metadata;
}
 
Example #22
Source File: JpaContentAutoConfigureRegistrar.java    From spring-content with Apache License 2.0 5 votes vote down vote up
@Override
protected void registerContentStoreBeanDefinitions(
		AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

	AnnotationMetadata metadata = new StandardAnnotationMetadata(
			EnableJpaContentAutoConfiguration.class);
	AnnotationAttributes attributes = new AnnotationAttributes(
			metadata.getAnnotationAttributes(this.getAnnotation().getName()));

	String[] basePackages = this.getBasePackages();

	Set<GenericBeanDefinition> definitions = StoreUtils.getStoreCandidates(this.getEnvironment(), this.getResourceLoader(), basePackages, multipleStoreImplementationsDetected(), getIdentifyingTypes());

	this.buildAndRegisterDefinitions(importingClassMetadata, registry, attributes, basePackages, definitions);
}
 
Example #23
Source File: ImportAwareTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void metadataFromImportsTwoThenOne() {
	AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
			ConfigurationTwo.class, ConfigurationOne.class)
			.getBean(MetadataHolder.class).importMetadata;
	assertEquals(ConfigurationOne.class,
			((StandardAnnotationMetadata) importMetadata).getIntrospectedClass());
}
 
Example #24
Source File: ImportAwareTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void metadataFromImportsOneThenTwo() {
	AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
			ConfigurationOne.class, ConfigurationTwo.class)
			.getBean(MetadataHolder.class).importMetadata;
	assertEquals(ConfigurationOne.class,
			((StandardAnnotationMetadata) importMetadata).getIntrospectedClass());
}
 
Example #25
Source File: ConfigurationClassParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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) {
		// Try reading the class file via ASM for deterministic declaration order...
		// Unfortunately, the JVM's standard reflection returns methods in arbitrary
		// 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;
}
 
Example #26
Source File: ConfigurationClass.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a new {@link ConfigurationClass} with the given name.
 * @param clazz the underlying {@link Class} to represent
 * @param beanName name of the {@code @Configuration} class bean
 * @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
 */
public ConfigurationClass(Class<?> clazz, String beanName) {
	Assert.notNull(beanName, "Bean name must not be null");
	this.metadata = new StandardAnnotationMetadata(clazz, true);
	this.resource = new DescriptiveResource(clazz.getName());
	this.beanName = beanName;
}
 
Example #27
Source File: ConfigurationClassParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
public SourceClass(Object source) {
	this.source = source;
	if (source instanceof Class) {
		this.metadata = new StandardAnnotationMetadata((Class<?>) source, true);
	}
	else {
		this.metadata = ((MetadataReader) source).getAnnotationMetadata();
	}
}
 
Example #28
Source File: ConfigurationClassParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Factory method to obtain a {@link SourceClass} from a {@link ConfigurationClass}.
 */
private SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException {
	AnnotationMetadata metadata = configurationClass.getMetadata();
	if (metadata instanceof StandardAnnotationMetadata) {
		return asSourceClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
	}
	return asSourceClass(metadata.getClassName());
}
 
Example #29
Source File: ConfigurationClassParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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) {
		// Try reading the class file via ASM for deterministic declaration order...
		// Unfortunately, the JVM's standard reflection returns methods in arbitrary
		// 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;
}
 
Example #30
Source File: AnnotatedGenericBeanDefinition.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
 * allowing for ASM-based processing and avoidance of early loading of the bean class.
 * Note that this constructor is functionally equivalent to
 * {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
 * ScannedGenericBeanDefinition}, however the semantics of the latter indicate that a
 * bean was discovered specifically via component-scanning as opposed to other means.
 * @param metadata the annotation metadata for the bean class in question
 * @since 3.1.1
 */
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
	Assert.notNull(metadata, "AnnotationMetadata must not be null");
	if (metadata instanceof StandardAnnotationMetadata) {
		setBeanClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
	}
	else {
		setBeanClassName(metadata.getClassName());
	}
	this.metadata = metadata;
}