·
@PostConstruct & @PreDestroy annotated methods:
* must be public
* must take no arguments
* can only return void
* can take arguments
#spring #certificationquestion #vcp
Answer: Annotated methods can have any visibility but must take no parameters and only return void
These annotations will be used inside your components.
Notice that @PostConstruct and @PreDestroy are both annotations annotating methods that return void with no arguments.
That's the contract.
@PostConstruct will be used during the initialization phase.
It will be executed right after setting the dependencies.
And @PreDestroy will be executed during the destruction phase when we destroy the component.