Posts

Showing posts with the label Spring Core

Spring initMethod and destroyMethod Example

Image
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://

Spring init-method and destroy-method - Example

Image
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

Spring InitializingBean and DisposableBean - Example

Image
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