Sobes.tech
Junior — Middle

Have you used the @PostConstruct annotation in a Spring application?

sobes.tech AI

Answer from AI

The @PostConstruct annotation in Spring is used to designate a method that should be executed immediately after Spring creates a bean and performs dependency injection, but before the bean is available for use. This is convenient for resource initialization or configuration logic.

Example of usage:

@Component
public class MyService {

    @PostConstruct
    public void init() {
        // initialization code, e.g., loading configuration
        System.out.println("Bean initialized");
    }
}

Thus, a method annotated with @PostConstruct is guaranteed to be called once after the bean is created and dependencies are injected.

Have you used the @PostConstruct annotation in a… - sobes.tech