@@ -4142,7 +4142,8 @@ unnecessarily couples the code to Spring. Alternatively, use
4142
4142
the <<beans-postconstruct-and-predestroy-annotations, `@PostConstruct`>> annotation or
4143
4143
specify a POJO initialization method. In the case of XML-based configuration metadata,
4144
4144
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:
4146
4147
4147
4148
[source,xml,indent=0]
4148
4149
[subs="verbatim,quotes"]
@@ -4201,8 +4202,9 @@ It is recommended that you do not use the `DisposableBean` callback interface be
4201
4202
unnecessarily couples the code to Spring. Alternatively, use
4202
4203
the <<beans-postconstruct-and-predestroy-annotations, `@PreDestroy`>> annotation or
4203
4204
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:
4206
4208
4207
4209
[source,xml,indent=0]
4208
4210
[subs="verbatim,quotes"]
@@ -4244,6 +4246,15 @@ is exactly the same as:
4244
4246
4245
4247
but does not couple the code to Spring.
4246
4248
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
+ ====
4247
4258
4248
4259
[[beans-factory-lifecycle-default-init-destroy-methods]]
4249
4260
===== Default initialization and destroy methods
@@ -7250,6 +7261,15 @@ on the `bean` element:
7250
7261
}
7251
7262
----
7252
7263
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
+
7253
7273
Of course, in the case of `Foo` above, it would be equally as valid to call the `init()`
7254
7274
method directly during construction:
7255
7275
@@ -7262,7 +7282,7 @@ method directly during construction:
7262
7282
public Foo foo() {
7263
7283
Foo foo = new Foo();
7264
7284
foo.init();
7265
- return foo;
7285
+ return foo;
7266
7286
}
7267
7287
7268
7288
// ...
0 commit comments