@PostConstruct
An annotation marking a bean method to run once, after dependency injection and before the bean is used.
In more detail
Use it to open resources the bean owns or validate required state; if it throws, startup fails with a useful message instead of leaving a half-ready bean. It comes from the Jakarta Annotations specification.
Example
@PostConstruct void open() { }Related terms
- @PreDestroy — An annotation marking a bean method to run while the application context is closing, to release resources the bean owns.
- bean lifecycle — The stages a Spring bean passes through: construction, dependency injection, initialization, use, and destruction when the context closes.
- Jakarta EE — The family of Java enterprise specifications, run by the Eclipse Foundation, that defines standard APIs such as Persistence, Validation and Annotations.
Taught in
- The Spring Bean Lifecycle — Modern Java: Virtual Threads & High-Throughput Services