Java 5 Closeable and Java 7 AutoCloseable automatically detected as destroy methods
Also, @Bean destroy method inference not applying for DisposableBean implementers anymore (avoiding double destruction). Issue: SPR-10034
This commit is contained in:
@@ -207,7 +207,6 @@ public @interface Bean {
|
||||
* application context, for example a {@code close()} method on a JDBC {@code
|
||||
* DataSource} implementation, or a Hibernate {@code SessionFactory} object.
|
||||
* The method must have no arguments but may throw any exception.
|
||||
*
|
||||
* <p>As a convenience to the user, the container will attempt to infer a destroy
|
||||
* method against an object returned from the {@code @Bean} method. For example, given a
|
||||
* {@code @Bean} method returning an Apache Commons DBCP {@code BasicDataSource}, the
|
||||
@@ -217,16 +216,16 @@ public @interface Bean {
|
||||
* 'close'. The method may be declared at any level of the inheritance hierarchy and
|
||||
* will be detected regardless of the return type of the {@code @Bean} method (i.e.,
|
||||
* detection occurs reflectively against the bean instance itself at creation time).
|
||||
*
|
||||
* <p>To disable destroy method inference for a particular {@code @Bean}, specify an
|
||||
* empty string as the value, e.g. {@code @Bean(destroyMethod="")}.
|
||||
*
|
||||
* empty string as the value, e.g. {@code @Bean(destroyMethod="")}. Note that the
|
||||
* {@link org.springframework.beans.factory.DisposableBean} and the
|
||||
* {@link java.io.Closeable}/{@link java.lang.AutoCloseable} interfaces will
|
||||
* nevertheless get detected and the corresponding destroy/close method invoked.
|
||||
* <p>Note: Only invoked on beans whose lifecycle is under the full control of the
|
||||
* factory, which is always the case for singletons but not guaranteed for any
|
||||
* other scope.
|
||||
*
|
||||
* @see org.springframework.context.ConfigurableApplicationContext#close()
|
||||
*/
|
||||
String destroyMethod() default AbstractBeanDefinition.INFER_METHOD;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user