|
16 | 16 |
|
17 | 17 | package org.springframework.beans.factory.support;
|
18 | 18 |
|
19 |
| -import java.io.Closeable; |
20 | 19 | import java.io.Serializable;
|
21 | 20 | import java.lang.reflect.InvocationTargetException;
|
22 | 21 | import java.lang.reflect.Method;
|
@@ -68,18 +67,6 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
68 | 67 |
|
69 | 68 | private static final Log logger = LogFactory.getLog(DisposableBeanAdapter.class);
|
70 | 69 |
|
71 |
| - private static Class<?> closeableInterface; |
72 |
| - |
73 |
| - static { |
74 |
| - try { |
75 |
| - closeableInterface = ClassUtils.forName("java.lang.AutoCloseable", |
76 |
| - DisposableBeanAdapter.class.getClassLoader()); |
77 |
| - } |
78 |
| - catch (ClassNotFoundException ex) { |
79 |
| - closeableInterface = Closeable.class; |
80 |
| - } |
81 |
| - } |
82 |
| - |
83 | 70 |
|
84 | 71 | private final Object bean;
|
85 | 72 |
|
@@ -191,7 +178,7 @@ private DisposableBeanAdapter(Object bean, String beanName, boolean invokeDispos
|
191 | 178 | private String inferDestroyMethodIfNecessary(Object bean, RootBeanDefinition beanDefinition) {
|
192 | 179 | String destroyMethodName = beanDefinition.getDestroyMethodName();
|
193 | 180 | if (AbstractBeanDefinition.INFER_METHOD.equals(destroyMethodName) ||
|
194 |
| - (destroyMethodName == null && closeableInterface.isInstance(bean))) { |
| 181 | + (destroyMethodName == null && bean instanceof AutoCloseable)) { |
195 | 182 | // Only perform destroy method inference or Closeable detection
|
196 | 183 | // in case of the bean not explicitly implementing DisposableBean
|
197 | 184 | if (!(bean instanceof DisposableBean)) {
|
@@ -406,7 +393,7 @@ protected Object writeReplace() {
|
406 | 393 | * @param beanDefinition the corresponding bean definition
|
407 | 394 | */
|
408 | 395 | public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefinition) {
|
409 |
| - if (bean instanceof DisposableBean || closeableInterface.isInstance(bean)) { |
| 396 | + if (bean instanceof DisposableBean || bean instanceof AutoCloseable) { |
410 | 397 | return true;
|
411 | 398 | }
|
412 | 399 | String destroyMethodName = beanDefinition.getDestroyMethodName();
|
|
0 commit comments