diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java index 85adb1daa7a4..8896f990ecbb 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java @@ -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. @@ -97,7 +97,7 @@ public List 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; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index 499b26086705..33463ea9da91 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -1637,21 +1637,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. *

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() @@ -1667,7 +1668,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)) {