Added "destroyBean(Object)" method to AutowireCapableBeanFactory

Driven by the need for implementing Bean Validation 1.1's "releaseInstance" method in SpringConstraintValidatorFactory, as a direct counterpart to the use of AutowireCapableBeanFactory's "createBean(Class)" in "getInstance".

Issue: SPR-8199
This commit is contained in:
Juergen Hoeller
2013-03-28 21:44:07 +01:00
parent 9f9dc34b53
commit 23bf5f563b
4 changed files with 52 additions and 5 deletions

View File

@@ -32,7 +32,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.security.auth.Subject;
import org.apache.commons.logging.Log;
@@ -41,6 +40,7 @@ import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.NotWritablePropertyException;
@@ -1552,6 +1552,23 @@ public class DefaultListableBeanFactoryTests {
assertNull(tb.getSpouse());
}
@Test
public void testCreateBean() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
TestBean tb = lbf.createBean(TestBean.class);
assertSame(lbf, tb.getBeanFactory());
lbf.destroyBean(tb);
}
@Test
public void testCreateBeanWithDisposableBean() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
DerivedTestBean tb = lbf.createBean(DerivedTestBean.class);
assertSame(lbf, tb.getBeanFactory());
lbf.destroyBean(tb);
assertTrue(tb.wasDestroyed());
}
@Test
public void testConfigureBean() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();