Spring initMethod and destroyMethod Example
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKqro4yWTorpsN9yB2MYwVHcbyWLjI5YNzfuJpwngrw58fqdo8hBejMeqIqnoLKw4Jr88zTzOSs4lVAeiuttfgBs7QsEnzqylRX5mGrKbycO6_bRauT7tEx7Vyx8PsKsRjRJX9p0jqs2VFKAdefbLARhIwhGNmtjbW8SKxDYWcU7Qt36bMmofleNK-mR5e/w400-h214/spring-initMethod-destroyMethod.png)
The initMethod and destroyMethod are attributes of Spring @Bean annotation to perform certain actions upon bean initialization and destruction. initMethod is called after bean initialization and the destroyMethod is called 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. initMethod and destroyMethod are alternatives to InitializingBean and DisposableBean . Related topic, Spring init-method and destroy-method - 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 :schemaLocation ="http://