提交 4c823a3f 编写于 作者: J Juergen Hoeller 提交者: unknown

DisposableBeanAdapter detects "shutdown" as a destroy method as well (for...

DisposableBeanAdapter detects "shutdown" as a destroy method as well (for EHCache CacheManager setup)

 Issue: SPR-9713
上级 0dcc0f22
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -61,6 +61,8 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
private static final String CLOSE_METHOD_NAME = "close";
private static final String SHUTDOWN_METHOD_NAME = "shutdown";
private static final Log logger = LogFactory.getLog(DisposableBeanAdapter.class);
private static Class closeableInterface;
......@@ -176,7 +178,12 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
return bean.getClass().getMethod(CLOSE_METHOD_NAME).getName();
}
catch (NoSuchMethodException ex) {
// no candidate destroy method found
try {
return bean.getClass().getMethod(SHUTDOWN_METHOD_NAME).getName();
}
catch (NoSuchMethodException ex2) {
// no candidate destroy method found
}
}
}
return null;
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -16,16 +16,21 @@
package org.springframework.context.annotation;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.io.Closeable;
import java.io.IOException;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
/**
* @author Chris Beams
* @author Juergen Hoeller
*/
public class DestroyMethodInferenceTests {
@Test
......@@ -39,6 +44,7 @@ public class DestroyMethodInferenceTests {
WithInheritedCloseMethod c4 = ctx.getBean("c4", WithInheritedCloseMethod.class);
WithInheritedCloseMethod c5 = ctx.getBean("c5", WithInheritedCloseMethod.class);
WithNoCloseMethod c6 = ctx.getBean("c6", WithNoCloseMethod.class);
WithLocalShutdownMethod c7 = ctx.getBean("c7", WithLocalShutdownMethod.class);
assertThat(c0.closed, is(false));
assertThat(c1.closed, is(false));
......@@ -47,6 +53,7 @@ public class DestroyMethodInferenceTests {
assertThat(c4.closed, is(false));
assertThat(c5.closed, is(false));
assertThat(c6.closed, is(false));
assertThat(c7.closed, is(false));
ctx.close();
assertThat("c0", c0.closed, is(true));
assertThat("c1", c1.closed, is(true));
......@@ -55,6 +62,7 @@ public class DestroyMethodInferenceTests {
assertThat("c4", c4.closed, is(true));
assertThat("c5", c5.closed, is(true));
assertThat("c6", c6.closed, is(false));
assertThat("c7", c7.closed, is(true));
}
@Test
......@@ -121,6 +129,11 @@ public class DestroyMethodInferenceTests {
public WithNoCloseMethod c6() {
return new WithNoCloseMethod();
}
@Bean
public WithLocalShutdownMethod c7() {
return new WithLocalShutdownMethod();
}
}
......@@ -149,4 +162,12 @@ public class DestroyMethodInferenceTests {
static class WithNoCloseMethod {
boolean closed = false;
}
static class WithLocalShutdownMethod {
boolean closed = false;
public void shutdown() {
closed = true;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册