Showing posts with the label InitializingBean

Spring InitializingBean and DisposableBean - Example

In Spring, the InitializingBean and DisposableBean interfaces can be used to interact with the spring container’s management lifecycle. The container calls the afterPropertiesSet() method from the InitializingBean and the destroy() method from the DisposableBean respectively to perform certain actions upon bean initialization and destruction. Annotations @PostConstruct and @PreDestroy, standardized by JSR-250, are generally considered the best practice for obtaining lifecycle callbacks in a modern Spring application. Utilizing these annotations designates that our beans are not bound to Spring-concrete interfaces. Using @PostConstruct and @PreDestroy in Spring - click here If you don't optate to utilize JSR-250, consider the bean definition metadata init-method and destroy-method. 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&q