DisposableBeanAdapter detects "shutdown" as a destroy method as well (for EHCache CacheManager setup)
Issue: SPR-9713
This commit is contained in:
parent
0dcc0f2227
commit
4c823a3f9b
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 CLOSE_METHOD_NAME = "close";
|
||||||
|
|
||||||
|
private static final String SHUTDOWN_METHOD_NAME = "shutdown";
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(DisposableBeanAdapter.class);
|
private static final Log logger = LogFactory.getLog(DisposableBeanAdapter.class);
|
||||||
|
|
||||||
private static Class closeableInterface;
|
private static Class closeableInterface;
|
||||||
|
|
@ -176,9 +178,14 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||||
return bean.getClass().getMethod(CLOSE_METHOD_NAME).getName();
|
return bean.getClass().getMethod(CLOSE_METHOD_NAME).getName();
|
||||||
}
|
}
|
||||||
catch (NoSuchMethodException ex) {
|
catch (NoSuchMethodException ex) {
|
||||||
|
try {
|
||||||
|
return bean.getClass().getMethod(SHUTDOWN_METHOD_NAME).getName();
|
||||||
|
}
|
||||||
|
catch (NoSuchMethodException ex2) {
|
||||||
// no candidate destroy method found
|
// no candidate destroy method found
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return beanDefinition.getDestroyMethodName();
|
return beanDefinition.getDestroyMethodName();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,16 +16,21 @@
|
||||||
|
|
||||||
package org.springframework.context.annotation;
|
package org.springframework.context.annotation;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
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 {
|
public class DestroyMethodInferenceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -39,6 +44,7 @@ public class DestroyMethodInferenceTests {
|
||||||
WithInheritedCloseMethod c4 = ctx.getBean("c4", WithInheritedCloseMethod.class);
|
WithInheritedCloseMethod c4 = ctx.getBean("c4", WithInheritedCloseMethod.class);
|
||||||
WithInheritedCloseMethod c5 = ctx.getBean("c5", WithInheritedCloseMethod.class);
|
WithInheritedCloseMethod c5 = ctx.getBean("c5", WithInheritedCloseMethod.class);
|
||||||
WithNoCloseMethod c6 = ctx.getBean("c6", WithNoCloseMethod.class);
|
WithNoCloseMethod c6 = ctx.getBean("c6", WithNoCloseMethod.class);
|
||||||
|
WithLocalShutdownMethod c7 = ctx.getBean("c7", WithLocalShutdownMethod.class);
|
||||||
|
|
||||||
assertThat(c0.closed, is(false));
|
assertThat(c0.closed, is(false));
|
||||||
assertThat(c1.closed, is(false));
|
assertThat(c1.closed, is(false));
|
||||||
|
|
@ -47,6 +53,7 @@ public class DestroyMethodInferenceTests {
|
||||||
assertThat(c4.closed, is(false));
|
assertThat(c4.closed, is(false));
|
||||||
assertThat(c5.closed, is(false));
|
assertThat(c5.closed, is(false));
|
||||||
assertThat(c6.closed, is(false));
|
assertThat(c6.closed, is(false));
|
||||||
|
assertThat(c7.closed, is(false));
|
||||||
ctx.close();
|
ctx.close();
|
||||||
assertThat("c0", c0.closed, is(true));
|
assertThat("c0", c0.closed, is(true));
|
||||||
assertThat("c1", c1.closed, is(true));
|
assertThat("c1", c1.closed, is(true));
|
||||||
|
|
@ -55,6 +62,7 @@ public class DestroyMethodInferenceTests {
|
||||||
assertThat("c4", c4.closed, is(true));
|
assertThat("c4", c4.closed, is(true));
|
||||||
assertThat("c5", c5.closed, is(true));
|
assertThat("c5", c5.closed, is(true));
|
||||||
assertThat("c6", c6.closed, is(false));
|
assertThat("c6", c6.closed, is(false));
|
||||||
|
assertThat("c7", c7.closed, is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -121,6 +129,11 @@ public class DestroyMethodInferenceTests {
|
||||||
public WithNoCloseMethod c6() {
|
public WithNoCloseMethod c6() {
|
||||||
return new WithNoCloseMethod();
|
return new WithNoCloseMethod();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public WithLocalShutdownMethod c7() {
|
||||||
|
return new WithLocalShutdownMethod();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -149,4 +162,12 @@ public class DestroyMethodInferenceTests {
|
||||||
static class WithNoCloseMethod {
|
static class WithNoCloseMethod {
|
||||||
boolean closed = false;
|
boolean closed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class WithLocalShutdownMethod {
|
||||||
|
boolean closed = false;
|
||||||
|
public void shutdown() {
|
||||||
|
closed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue