Spring init-method and destroy-method - Example
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiE2oYGai6BZjxp2WQ1Nwxq8gax57OCyk9Uiz7vZ-BmVXH_5DUekIYuvPhVlsXPohbD4eRsipyRdIP4Non4k4yfc2C2oQ2qcd5R63X_yMDSLgAGEi36xOdPFA4laKvhcDtv62YOUwa1JZwP5eUOICrPoh5FUl0lo8wvgbP1gk0wkY4tiGh9Mwp_n5l4SMyf/w400-h206/Spring-init-method-destroy-method.png)
The init-method and destroy-method are attributes of Spring bean configuration file to perform certain actions upon bean initialization and destruction. init-method is called after bean initialization and the destroy-method is called during before bean destruction by container. Annotations @PostConstruct and @PreDestroy , standardized by JSR-250, are generally considered the best practice for obtaining lifecycle callbacks in a modern Spring application. init-method and destroy-method are alternatives to InitializingBean and DisposableBean . Related topic, Spring initMethod and destroyMethod Example - click here Complete Example We are creating a simple maven project. You could clone the code from our GitHub repo. Final Project Directory Complete pom.xml <? xml version ="1.0" encoding ="UTF-8" ?> < project xmlns ="http://maven.apache.org/POM/4.0.0" xmlns: xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi :sche