Skip to content

Commit 6ff2abc

Browse files
committed
Document destroy method name inference
Update the developer guide to explicitly reference the (inferred) constant introduced in 38e9010. Also emphasis the fact that the (inferred) mode is enabled by default with Java config and how to disable it if necessary. Issue: SPR-12534
1 parent fd7153f commit 6ff2abc

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/asciidoc/index.adoc

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4142,7 +4142,8 @@ unnecessarily couples the code to Spring. Alternatively, use
41424142
the <<beans-postconstruct-and-predestroy-annotations, `@PostConstruct`>> annotation or
41434143
specify a POJO initialization method. In the case of XML-based configuration metadata,
41444144
you use the `init-method` attribute to specify the name of the method that has a void
4145-
no-argument signature. For example, the following definition:
4145+
no-argument signature. With Java config you use the `initMethod` attribute of `@Bean`,
4146+
see <<beans-java-lifecycle-callbacks>>. For example, the following:
41464147

41474148
[source,xml,indent=0]
41484149
[subs="verbatim,quotes"]
@@ -4201,8 +4202,9 @@ It is recommended that you do not use the `DisposableBean` callback interface be
42014202
unnecessarily couples the code to Spring. Alternatively, use
42024203
the <<beans-postconstruct-and-predestroy-annotations, `@PreDestroy`>> annotation or
42034204
specify a generic method that is supported by bean definitions. With XML-based
4204-
configuration metadata, you use the `destroy-method` attribute on the `<bean/>`. For
4205-
example, the following definition:
4205+
configuration metadata, you use the `destroy-method` attribute on the `<bean/>`. With
4206+
Java config you use the `destroyMethod` attribute of `@Bean`, see
4207+
<<beans-java-lifecycle-callbacks>>. For example, the following definition:
42064208

42074209
[source,xml,indent=0]
42084210
[subs="verbatim,quotes"]
@@ -4244,6 +4246,15 @@ is exactly the same as:
42444246

42454247
but does not couple the code to Spring.
42464248

4249+
[TIP]
4250+
====
4251+
The `destroy-method` attribute of a `<bean/>` element can have a special `(inferred)`
4252+
value to automatically detect either a `close` or `shutdown` public method on the
4253+
specific bean class. This special value can also be set on the
4254+
`default-destroy-method` to apply that behavior to a set of beans (see
4255+
<<beans-factory-lifecycle-default-init-destroy-methods>>). Note that this is the
4256+
default behavior with Java config.
4257+
====
42474258

42484259
[[beans-factory-lifecycle-default-init-destroy-methods]]
42494260
===== Default initialization and destroy methods
@@ -7250,6 +7261,15 @@ on the `bean` element:
72507261
}
72517262
----
72527263

7264+
[NOTE]
7265+
====
7266+
By default, beans defined using Java config having a `close` or `shutdown` public method
7267+
are automatically enlisted with a destruction callback. If you have a `close` or `public`
7268+
method and you do not wish it to be called when the container shuts down, simply add
7269+
`@Bean(destroyMethod="")` to your bean definition to disable the default `(inferred)`
7270+
mode.
7271+
====
7272+
72537273
Of course, in the case of `Foo` above, it would be equally as valid to call the `init()`
72547274
method directly during construction:
72557275

@@ -7262,7 +7282,7 @@ method directly during construction:
72627282
public Foo foo() {
72637283
Foo foo = new Foo();
72647284
foo.init();
7265-
return foo;
7285+
return foo;
72667286
}
72677287

72687288
// ...

0 commit comments

Comments
 (0)