Skip to content

Commit 721fa9d

Browse files
committed
SpringBeanAutowiringInterceptor eagerly releases BeanFactory if post-construction fails
Issue: SPR-10013
1 parent 20c4ba4 commit 721fa9d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/access/BeanFactoryReference.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 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.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.beans.factory.access;
1818

19-
import org.springframework.beans.FatalBeanException;
2019
import org.springframework.beans.factory.BeanFactory;
2120

2221
/**
@@ -49,11 +48,10 @@ public interface BeanFactoryReference {
4948
* <p>In an EJB usage scenario this would normally be called from
5049
* {@code ejbRemove()} and {@code ejbPassivate()}.
5150
* <p>This is safe to call multiple times.
52-
* @throws FatalBeanException if the {@code BeanFactory} cannot be released
5351
* @see BeanFactoryLocator
5452
* @see org.springframework.context.access.ContextBeanFactoryReference
5553
* @see org.springframework.context.ConfigurableApplicationContext#close()
5654
*/
57-
void release() throws FatalBeanException;
55+
void release();
5856

5957
}

spring-context/src/main/java/org/springframework/ejb/interceptor/SpringBeanAutowiringInterceptor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 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.
@@ -71,8 +71,6 @@
7171
* @see org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
7272
* @see org.springframework.context.access.ContextSingletonBeanFactoryLocator
7373
* @see #getBeanFactoryLocatorKey
74-
* @see org.springframework.ejb.support.AbstractEnterpriseBean#setBeanFactoryLocator
75-
* @see org.springframework.ejb.support.AbstractEnterpriseBean#setBeanFactoryLocatorKey
7674
*/
7775
public class SpringBeanAutowiringInterceptor {
7876

@@ -99,9 +97,15 @@ public void autowireBean(InvocationContext invocationContext) {
9997
invocationContext.proceed();
10098
}
10199
catch (RuntimeException ex) {
100+
doReleaseBean(invocationContext.getTarget());
102101
throw ex;
103102
}
103+
catch (Error err) {
104+
doReleaseBean(invocationContext.getTarget());
105+
throw err;
106+
}
104107
catch (Exception ex) {
108+
doReleaseBean(invocationContext.getTarget());
105109
// Cannot declare a checked exception on WebSphere here - so we need to wrap.
106110
throw new EJBException(ex);
107111
}

0 commit comments

Comments
 (0)