JavaAdvanced#spring

Explain Spring Bean lifecycle.

Instantiate → populate properties → BeanNameAware/BeanFactoryAware → postProcessBeforeInitialization → @PostConstruct / afterPropertiesSet / custom init → postProcessAfterInitialization → use → @PreDestroy / destroy.

Example
@Component
class MyBean {
  @PostConstruct void init() { System.out.println("initialized"); }
  @PreDestroy void cleanup() { System.out.println("destroyed"); }
}

Related Questions

1
JavaIntermediate#spring

What is the difference between Spring Boot and Spring Framework?

Open
2
JavaIntermediate#jpa

What is JPA vs Hibernate?

Open
3
JavaIntermediate#fundamentals

What is the difference between == and .equals() for Integer in Java?

Open