17
17
package org .springframework .context .annotation ;
18
18
19
19
import java .io .Closeable ;
20
- import java .io .IOException ;
21
20
22
21
import org .junit .Test ;
23
22
23
+ import org .springframework .beans .factory .DisposableBean ;
24
24
import org .springframework .context .ConfigurableApplicationContext ;
25
25
import org .springframework .context .support .GenericXmlApplicationContext ;
26
26
@@ -46,6 +46,7 @@ public void beanMethods() {
46
46
WithNoCloseMethod c6 = ctx .getBean ("c6" , WithNoCloseMethod .class );
47
47
WithLocalShutdownMethod c7 = ctx .getBean ("c7" , WithLocalShutdownMethod .class );
48
48
WithInheritedCloseMethod c8 = ctx .getBean ("c8" , WithInheritedCloseMethod .class );
49
+ WithDisposableBean c9 = ctx .getBean ("c9" , WithDisposableBean .class );
49
50
50
51
assertThat (c0 .closed , is (false ));
51
52
assertThat (c1 .closed , is (false ));
@@ -56,6 +57,7 @@ public void beanMethods() {
56
57
assertThat (c6 .closed , is (false ));
57
58
assertThat (c7 .closed , is (false ));
58
59
assertThat (c8 .closed , is (false ));
60
+ assertThat (c9 .closed , is (false ));
59
61
ctx .close ();
60
62
assertThat ("c0" , c0 .closed , is (true ));
61
63
assertThat ("c1" , c1 .closed , is (true ));
@@ -66,6 +68,7 @@ public void beanMethods() {
66
68
assertThat ("c6" , c6 .closed , is (false ));
67
69
assertThat ("c7" , c7 .closed , is (true ));
68
70
assertThat ("c8" , c8 .closed , is (false ));
71
+ assertThat ("c9" , c9 .closed , is (true ));
69
72
}
70
73
71
74
@ Test
@@ -123,7 +126,7 @@ public Closeable c4() {
123
126
public WithInheritedCloseMethod c5 () {
124
127
return new WithInheritedCloseMethod () {
125
128
@ Override
126
- public void close () throws IOException {
129
+ public void close () {
127
130
throw new IllegalStateException ("close() should not be called" );
128
131
}
129
132
@ SuppressWarnings ("unused" )
@@ -147,6 +150,11 @@ public WithLocalShutdownMethod c7() {
147
150
public WithInheritedCloseMethod c8 () {
148
151
return new WithInheritedCloseMethod ();
149
152
}
153
+
154
+ @ Bean (destroyMethod = "" )
155
+ public WithDisposableBean c9 () {
156
+ return new WithDisposableBean ();
157
+ }
150
158
}
151
159
152
160
@@ -175,7 +183,18 @@ static class WithInheritedCloseMethod implements Closeable {
175
183
boolean closed = false ;
176
184
177
185
@ Override
178
- public void close () throws IOException {
186
+ public void close () {
187
+ closed = true ;
188
+ }
189
+ }
190
+
191
+
192
+ static class WithDisposableBean implements DisposableBean {
193
+
194
+ boolean closed = false ;
195
+
196
+ @ Override
197
+ public void destroy () {
179
198
closed = true ;
180
199
}
181
200
}
0 commit comments