boot

@PreConstruct and @PostConstruct annotation Spring Boot Example

@PreConstruct and @PostConstruct annotation Spring Boot Example

@PostConstruct: This method is called after the Spring bean (in this case, ExampleBean) has been created and all dependencies have been injected. It’s an ideal place to put initialization logic. @PreDestroy: This method is called before the Spring bean is destroyed. It’s where you can place cleanup logic, such as closing resources.Create Spring Boot Application DemoApplication package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } Enter fullscreen mode Exit fullscreen mode ExampleBean package com.example.demo; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @Component public class ExampleBean { public ExampleBean() {…
Read More
No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.