Clarify destroy method suppression for DisposableBean vs (Auto)Closeable

Issue: SPR-16078

(cherry picked from commit dff2c84)
This commit is contained in:
Juergen Hoeller
2017-10-16 23:11:19 +02:00
parent 2d05e538fb
commit d1b5b5d2f7
2 changed files with 29 additions and 6 deletions

View File

@@ -17,10 +17,10 @@
package org.springframework.context.annotation;
import java.io.Closeable;
import java.io.IOException;
import org.junit.Test;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
@@ -46,6 +46,7 @@ public class DestroyMethodInferenceTests {
WithNoCloseMethod c6 = ctx.getBean("c6", WithNoCloseMethod.class);
WithLocalShutdownMethod c7 = ctx.getBean("c7", WithLocalShutdownMethod.class);
WithInheritedCloseMethod c8 = ctx.getBean("c8", WithInheritedCloseMethod.class);
WithDisposableBean c9 = ctx.getBean("c9", WithDisposableBean.class);
assertThat(c0.closed, is(false));
assertThat(c1.closed, is(false));
@@ -56,6 +57,7 @@ public class DestroyMethodInferenceTests {
assertThat(c6.closed, is(false));
assertThat(c7.closed, is(false));
assertThat(c8.closed, is(false));
assertThat(c9.closed, is(false));
ctx.close();
assertThat("c0", c0.closed, is(true));
assertThat("c1", c1.closed, is(true));
@@ -66,6 +68,7 @@ public class DestroyMethodInferenceTests {
assertThat("c6", c6.closed, is(false));
assertThat("c7", c7.closed, is(true));
assertThat("c8", c8.closed, is(false));
assertThat("c9", c9.closed, is(true));
}
@Test
@@ -123,7 +126,7 @@ public class DestroyMethodInferenceTests {
public WithInheritedCloseMethod c5() {
return new WithInheritedCloseMethod() {
@Override
public void close() throws IOException {
public void close() {
throw new IllegalStateException("close() should not be called");
}
@SuppressWarnings("unused")
@@ -147,6 +150,11 @@ public class DestroyMethodInferenceTests {
public WithInheritedCloseMethod c8() {
return new WithInheritedCloseMethod();
}
@Bean(destroyMethod = "")
public WithDisposableBean c9() {
return new WithDisposableBean();
}
}
@@ -175,7 +183,18 @@ public class DestroyMethodInferenceTests {
boolean closed = false;
@Override
public void close() throws IOException {
public void close() {
closed = true;
}
}
static class WithDisposableBean implements DisposableBean {
boolean closed = false;
@Override
public void destroy() {
closed = true;
}
}