In a managed bean, @PostConstruct is called after the regular Java object constructor.
Why would I use @PostConstruct to initialize by bean, instead of the regular constructor itself?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
because when the constructor is called, the bean is not yet initialized – i.e. no dependencies are injected. In the
@PostConstructmethod the bean is fully initialized and you can use the dependencies.because this is the contract that guarantees that this method will be invoked only once in the bean lifecycle. It may happen (though unlikely) that a bean is instantiated multiple times by the container in its internal working, but it guarantees that
@PostConstructwill be invoked only once.