Skip to content

Commit

Permalink
Use getType with allowFactoryBeanInit=false during advisor retrieval
Browse files Browse the repository at this point in the history
Closes gh-25546
  • Loading branch information
jhoeller committed Aug 10, 2020
1 parent bd65762 commit 7d56c30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,7 +97,7 @@ public List<Advisor> buildAspectJAdvisors() {
}
// We must be careful not to instantiate beans eagerly as in this case they
// would be cached by the Spring container but would not have been weaved.
Class<?> beanType = this.beanFactory.getType(beanName);
Class<?> beanType = this.beanFactory.getType(beanName, false);
if (beanType == null) {
continue;
}
Expand Down
Expand Up @@ -1621,21 +1621,22 @@ protected boolean isFactoryBean(String beanName, RootBeanDefinition mbd) {
/**
* Determine the bean type for the given FactoryBean definition, as far as possible.
* Only called if there is no singleton instance registered for the target bean
* already. Implementations are only allowed to instantiate the factory bean if
* {@code allowInit} is {@code true}, otherwise they should try to determine the
* result through other means.
* already. The implementation is allowed to instantiate the target factory bean if
* {@code allowInit} is {@code true} and the type cannot be determined another way;
* otherwise it is restricted to introspecting signatures and related metadata.
* <p>If no {@link FactoryBean#OBJECT_TYPE_ATTRIBUTE} if set on the bean definition
* and {@code allowInit} is {@code true}, the default implementation will create
* the FactoryBean via {@code getBean} to call its {@code getObjectType} method.
* Subclasses are encouraged to optimize this, typically by inspecting the generic
* signature of the factory bean class or the factory method that creates it. If
* subclasses do instantiate the FactoryBean, they should consider trying the
* {@code getObjectType} method without fully populating the bean. If this fails, a
* full FactoryBean creation as performed by this implementation should be used as
* fallback.
* signature of the factory bean class or the factory method that creates it.
* If subclasses do instantiate the FactoryBean, they should consider trying the
* {@code getObjectType} method without fully populating the bean. If this fails,
* a full FactoryBean creation as performed by this implementation should be used
* as fallback.
* @param beanName the name of the bean
* @param mbd the merged bean definition for the bean
* @param allowInit if initialization of the FactoryBean is permitted
* @param allowInit if initialization of the FactoryBean is permitted if the type
* cannot be determined another way
* @return the type for the bean if determinable, otherwise {@code ResolvableType.NONE}
* @since 5.2
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
Expand All @@ -1651,7 +1652,7 @@ protected ResolvableType getTypeForFactoryBean(String beanName, RootBeanDefiniti
try {
FactoryBean<?> factoryBean = doGetBean(FACTORY_BEAN_PREFIX + beanName, FactoryBean.class, null, true);
Class<?> objectType = getTypeForFactoryBean(factoryBean);
return (objectType != null) ? ResolvableType.forClass(objectType) : ResolvableType.NONE;
return (objectType != null ? ResolvableType.forClass(objectType) : ResolvableType.NONE);
}
catch (BeanCreationException ex) {
if (ex.contains(BeanCurrentlyInCreationException.class)) {
Expand Down

0 comments on commit 7d56c30

Please sign in to comment.