CDI managed bean classes and their superclasses support the annotations for initializing and for preparing for the destruction of a bean. These annotation are defined in JSR 250: Common Annotations for the Java platform.
To Initialize a Managed Bean Using the @PostConstruct AnnotationInitializing a managed bean specifies the lifecycle callback method that the CDI framework should call after dependency injection but before the class is put into service.
When the managed bean is injected into a component, CDI calls the method after all injection has occurred and after all initializers have been called.
Note - As mandated in JSR 250, if the annotated method is declared in a superclass, the method is called unless a subclass of the declaring class overrides the method.
The UserNumberBean managed bean in The guessnumber CDI Example uses @PostConstruct to annotate a method that resets all bean fields:
@PostConstruct public void reset () { this.minimum = 0; this.userNumber = 0; this.remainingGuesses = 0; this.maximum = maxNumber; this.number = randomInt.get(); }
Preparing for the destruction of a managed bean specifies the lifecycle call back method that signals that an application component is about to be destroyed by the container.
In this method, perform any cleanup that is required before the bean is destroyed, such as releasing a resource that the bean has been holding.
CDI calls this method before starting to destroy the bean.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4