diff --git a/src/reference/docbook/beans-customizing.xml b/src/reference/docbook/beans-customizing.xml index acca5514a7..9e5c4284b9 100644 --- a/src/reference/docbook/beans-customizing.xml +++ b/src/reference/docbook/beans-customizing.xml @@ -13,18 +13,25 @@
Lifecycle callbacks - - To interact with the container's management of the bean lifecycle, you can implement the Spring InitializingBean and DisposableBean interfaces. The container calls afterPropertiesSet() for the former and destroy() for the latter to allow the bean to perform certain actions upon initialization and destruction of - your beans. You can also achieve the same integration with the container - without coupling your classes to Spring interfaces through the use of - init-method and destroy method object definition metadata. + your beans. + + + The JSR-250 @PostConstruct and + @PreDestroy annotations are generally + considered best practice for receiving lifecycle callbacks in a modern + Spring application. Using these annotations means that your beans are not + coupled to Spring specific interfaces. For details see + . + If you don't want to use the JSR-250 annotations but you are still + looking to remove coupling consider the use of init-method and destroy-method + object definition metadata. + Internally, the Spring Framework uses BeanPostProcessor implementations to @@ -57,7 +64,9 @@ It is recommended that you do not use the InitializingBean interface because it - unnecessarily couples the code to Spring. Alternatively, specify a POJO + unnecessarily couples the code to Spring. Alternatively, use the + + @PostConstruct annotation or specify a POJO initialization method. In the case of XML-based configuration metadata, you use the init-method attribute to specify the name of the method that has a void no-argument signature. For example, the @@ -99,7 +108,9 @@ It is recommended that you do not use the DisposableBean callback interface because - it unnecessarily couples the code to Spring. Alternatively, specify a + it unnecessarily couples the code to Spring. Alternatively, use the + + @PreDestroy annotation or specify a generic method that is supported by bean definitions. With XML-based configuration metadata, you use the destroy-method attribute on the <bean/>. For example, the