Skip to content

Commit 7d56c30

Browse files
committed
Use getType with allowFactoryBeanInit=false during advisor retrieval
Closes gh-25546
1 parent bd65762 commit 7d56c30

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -97,7 +97,7 @@ public List<Advisor> buildAspectJAdvisors() {
9797
}
9898
// We must be careful not to instantiate beans eagerly as in this case they
9999
// would be cached by the Spring container but would not have been weaved.
100-
Class<?> beanType = this.beanFactory.getType(beanName);
100+
Class<?> beanType = this.beanFactory.getType(beanName, false);
101101
if (beanType == null) {
102102
continue;
103103
}

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,21 +1621,22 @@ protected boolean isFactoryBean(String beanName, RootBeanDefinition mbd) {
16211621
/**
16221622
* Determine the bean type for the given FactoryBean definition, as far as possible.
16231623
* Only called if there is no singleton instance registered for the target bean
1624-
* already. Implementations are only allowed to instantiate the factory bean if
1625-
* {@code allowInit} is {@code true}, otherwise they should try to determine the
1626-
* result through other means.
1624+
* already. The implementation is allowed to instantiate the target factory bean if
1625+
* {@code allowInit} is {@code true} and the type cannot be determined another way;
1626+
* otherwise it is restricted to introspecting signatures and related metadata.
16271627
* <p>If no {@link FactoryBean#OBJECT_TYPE_ATTRIBUTE} if set on the bean definition
16281628
* and {@code allowInit} is {@code true}, the default implementation will create
16291629
* the FactoryBean via {@code getBean} to call its {@code getObjectType} method.
16301630
* Subclasses are encouraged to optimize this, typically by inspecting the generic
1631-
* signature of the factory bean class or the factory method that creates it. If
1632-
* subclasses do instantiate the FactoryBean, they should consider trying the
1633-
* {@code getObjectType} method without fully populating the bean. If this fails, a
1634-
* full FactoryBean creation as performed by this implementation should be used as
1635-
* fallback.
1631+
* signature of the factory bean class or the factory method that creates it.
1632+
* If subclasses do instantiate the FactoryBean, they should consider trying the
1633+
* {@code getObjectType} method without fully populating the bean. If this fails,
1634+
* a full FactoryBean creation as performed by this implementation should be used
1635+
* as fallback.
16361636
* @param beanName the name of the bean
16371637
* @param mbd the merged bean definition for the bean
1638-
* @param allowInit if initialization of the FactoryBean is permitted
1638+
* @param allowInit if initialization of the FactoryBean is permitted if the type
1639+
* cannot be determined another way
16391640
* @return the type for the bean if determinable, otherwise {@code ResolvableType.NONE}
16401641
* @since 5.2
16411642
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
@@ -1651,7 +1652,7 @@ protected ResolvableType getTypeForFactoryBean(String beanName, RootBeanDefiniti
16511652
try {
16521653
FactoryBean<?> factoryBean = doGetBean(FACTORY_BEAN_PREFIX + beanName, FactoryBean.class, null, true);
16531654
Class<?> objectType = getTypeForFactoryBean(factoryBean);
1654-
return (objectType != null) ? ResolvableType.forClass(objectType) : ResolvableType.NONE;
1655+
return (objectType != null ? ResolvableType.forClass(objectType) : ResolvableType.NONE);
16551656
}
16561657
catch (BeanCreationException ex) {
16571658
if (ex.contains(BeanCurrentlyInCreationException.class)) {

0 commit comments

Comments
 (0)