Add INFER_METHOD constant and update @Bean Javadoc
In anticipation of 'destroy method inference' feature, introduce ConfigurationClassUtils#INFER_METHOD and update @Bean#destroyMethod to reflect its use. Issue: SPR-8751
This commit is contained in:
parent
6b4ef0237c
commit
870d903417
|
|
@ -168,11 +168,21 @@ public @interface Bean {
|
||||||
* The optional name of a method to call on the bean instance upon closing the
|
* The optional name of a method to call on the bean instance upon closing the
|
||||||
* application context, for example a {@code close()} method on a {@code DataSource}.
|
* application context, for example a {@code close()} method on a {@code DataSource}.
|
||||||
* The method must have no arguments but may throw any exception.
|
* 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 based on the return type of the {@code @Bean} method. For example, given a
|
||||||
|
* {@code @Bean} method returning an Apache Commons DBCP {@code BasicDataSource}, the
|
||||||
|
* container will notice the {@code close()} method available on that type and
|
||||||
|
* automatically register it as the {@code destroyMethod}. By contrast, for a return
|
||||||
|
* type of JDBC {@code DataSource} interface (which does not declare a {@code close()}
|
||||||
|
* method, no inference is possible and the user must fall back to manually declaring
|
||||||
|
* {@code @Bean(destroyMethod="close")}.
|
||||||
|
* <p>To disable destroy method inference for a particular {@code @Bean}, specify an
|
||||||
|
* empty string as the value, e.g. {@code @Bean(destroyMethod="")}.
|
||||||
* <p>Note: Only invoked on beans whose lifecycle is under the full control of the
|
* <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
|
* factory, which is always the case for singletons but not guaranteed
|
||||||
* for any other scope.
|
* for any other scope.
|
||||||
* @see org.springframework.context.ConfigurableApplicationContext#close()
|
* @see org.springframework.context.ConfigurableApplicationContext#close()
|
||||||
*/
|
*/
|
||||||
String destroyMethod() default "";
|
String destroyMethod() default ConfigurationClassUtils.INFER_METHOD;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ abstract class ConfigurationClassUtils {
|
||||||
private static final String CONFIGURATION_CLASS_ATTRIBUTE =
|
private static final String CONFIGURATION_CLASS_ATTRIBUTE =
|
||||||
Conventions.getQualifiedAttributeName(ConfigurationClassPostProcessor.class, "configurationClass");
|
Conventions.getQualifiedAttributeName(ConfigurationClassPostProcessor.class, "configurationClass");
|
||||||
|
|
||||||
|
static final String INFER_METHOD = ""; // TODO SPR-8751 update to '-' or some such
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given bean definition is a candidate for a configuration class,
|
* Check whether the given bean definition is a candidate for a configuration class,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue