Configuring Methods Using Annotations in Web Applications
Use
You can define the moment when a method is called by using the corresponding annotations.
There are two annotations for configuring method invocation:
-
@PostConstruct
This annotation specifies that the method will be called before all lifecycle methods are called.
-
@PreDestroy
This annotation specifies that the method will be called before the servlet object is destroyed.
Procedure
Using the @PostConstruct Annotation
Use this annotation at method level without any attributes.
Using the @PreDestroy Annotation
Use this annotation at method level without any attributes.