spring-framework/org.springframework.context
Chris Beams 38e90105a0 Support destroy method inference
Anywhere the value of a destroy method may be expressed, specifying
the value "(inferred)" now indicates that the container should attempt
to automatically discover a destroy method. This functionality is
currently limited to detecting public, no-arg methods named 'close';
this is particularly useful for commonly used types such as Hibernate
SessionFactory most JDBC DataSource implementations, JMS connection
factories, and so forth.

This special value is captured as the constant
AbstractBeanDefinition#INFER_METHOD, which in turn serves as the default
value of the @Bean#destroyMethod attribute.

For example in the following case

    @Bean
    public BasicDataSource dataSource() { ... }

the container will automatically detect BasicDataSource#close and invoke
it when the enclosing ApplicationContext is closed. This is exactly
equivalent to

    @Bean(destroyMethod="(inferred)")
    public BasicDataSource dataSource() { ... }

A user may override this inference-by-default convention simply by
specifying a different method

    @Bean(destroyMethod="myClose")
    public MyBasicDataSource dataSource() { ... }

or, in the case of a bean that has an otherwise inferrable 'close'
method, but the user wishes to disable handling it entirely, an empty
string may be specified

    @Bean(destroyMethod="")
    public MyBasicDataSource dataSource() { ... }

The special destroy method name "(inferred)" may also be specified in
an XML context, e.g.

    <bean destroy-method="(inferred)">
        or
    <beans default-destroy-method="(inferred)">

Note that "(inferred)" is the default value for @Bean#destroyMethod,
but NOT for the destroy-method and default-destroy-method attributes
in the spring-beans XML schema.

The principal reason for introducing this feature is to avoid forcing
@Configuration class users to type destroyMethod="close" every time a
closeable bean is configured. This kind of boilerplate is easily
forgotten, and this simple convention means the right thing is done
by default, while allowing the user full control over customization or
disablement in special cases.

Issue: SPR-8751
2011-10-12 02:09:04 +00:00
..
.settings Merge 3.1.0 development branch into trunk 2010-10-25 19:48:20 +00:00
src Support destroy method inference 2011-10-12 02:09:04 +00:00
.classpath [SPR-8222] Upgraded to JUnit 4.9. 2011-08-30 13:16:12 +00:00
.project revised cache abstraction 2011-05-18 17:43:13 +00:00
.springBeans Remove "Feature" support introduced in 3.1 M1 2011-05-06 19:03:52 +00:00
build.xml + upgrade to AspectJ 1.6.8 2010-02-04 11:46:21 +00:00
context.iml introduced ForkJoinPoolFactoryBean for Java 7 (alternative: add new jsr166.jar to Java 6) 2011-08-15 16:41:55 +00:00
ivy.xml introduced ForkJoinPoolFactoryBean for Java 7 (alternative: add new jsr166.jar to Java 6) 2011-08-15 16:41:55 +00:00
pom.xml Update ejb, inject-tck, jsr166 deps in context pom 2011-08-20 03:01:49 +00:00
template.mf fixed Hibernate Validator import range 2011-08-18 23:13:56 +00:00