Skip to content

Commit 61894af

Browse files
committed
Expose FactoryBean attribute exception as BeanDefinitionStoreException
Closes gh-33117
1 parent c74666a commit 61894af

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Diff for: spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -843,10 +843,17 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
843843
*/
844844
@Override
845845
protected ResolvableType getTypeForFactoryBean(String beanName, RootBeanDefinition mbd, boolean allowInit) {
846+
ResolvableType result;
847+
846848
// Check if the bean definition itself has defined the type with an attribute
847-
ResolvableType result = getTypeForFactoryBeanFromAttributes(mbd);
848-
if (result != ResolvableType.NONE) {
849-
return result;
849+
try {
850+
result = getTypeForFactoryBeanFromAttributes(mbd);
851+
if (result != ResolvableType.NONE) {
852+
return result;
853+
}
854+
}
855+
catch (IllegalArgumentException ex) {
856+
throw new BeanDefinitionStoreException(mbd.getResourceDescription(), beanName, ex.getMessage());
850857
}
851858

852859
// For instance supplied beans, try the target type and bean class immediately

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -1716,9 +1716,14 @@ protected boolean isFactoryBean(String beanName, RootBeanDefinition mbd) {
17161716
* @see #getBean(String)
17171717
*/
17181718
protected ResolvableType getTypeForFactoryBean(String beanName, RootBeanDefinition mbd, boolean allowInit) {
1719-
ResolvableType result = getTypeForFactoryBeanFromAttributes(mbd);
1720-
if (result != ResolvableType.NONE) {
1721-
return result;
1719+
try {
1720+
ResolvableType result = getTypeForFactoryBeanFromAttributes(mbd);
1721+
if (result != ResolvableType.NONE) {
1722+
return result;
1723+
}
1724+
}
1725+
catch (IllegalArgumentException ex) {
1726+
throw new BeanDefinitionStoreException(mbd.getResourceDescription(), beanName, ex.getMessage());
17221727
}
17231728

17241729
if (allowInit && mbd.isSingleton()) {

0 commit comments

Comments
 (0)