| Author |
Many @PostConstruct methods?
|
Raf Szczypiorski
Ranch Hand
Joined: Aug 21, 2008
Posts: 383
|
|
Hi. Can a bean have many @PostConstruct methods? I creted 2, but the container always invokes only one of them (the second one defined in the file, glasssfish v2). The same for @PreDestroy. However, the specs say:
The container then calls the PostConstruct lifecycle callback interceptor method(s) for the bean, if any.
How is it, then?
Thanks.
|
 |
Ralph Jaus
Ranch Hand
Joined: Apr 27, 2008
Posts: 342
|
|
There can be at most one lifecycle callback method per lifecycle event in a class.
The following classes can contain lifecycle callback methods:
- interceptor classes and their superclasses
- bean classes and their superclasses
If a lifecycle event occurs at first the lifecycle callback methods in the interceptor classes
(and their superclasses) are called and afterwards the lifecycle callback method in the
bean class (and those in the superclasses of the bean class).
For more details concerning the invocation order and overriding see core spec 12.4.1
|
SCJP 5 (98%) - SCBCD 5 (98%)
|
 |
Raf Szczypiorski
Ranch Hand
Joined: Aug 21, 2008
Posts: 383
|
|
|
Thank you.
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
|
Ralf: Here the question was as to which method out of the two marked as @PostConstruct will be invoked?
|
SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
|
 |
Treimin Clark
Ranch Hand
Joined: Nov 12, 2008
Posts: 757
|
|
Jothi Shankar Kumar wrote:Ralf: Here the question was as to which method out of the two marked as @PostConstruct will be invoked?
As I know, it is unpredictable.
|
 |
Ralph Jaus
Ranch Hand
Joined: Apr 27, 2008
Posts: 342
|
|
Ralf: Here the question was as to which method out of the two marked as @PostConstruct will be invoked?
Having more than one post-construct method (the same holds for any other lifecycle event) in one class is not compliant with the ejb 3.0 spec. So the behavoir of the system is undefinied. But if there are several post-construct methods distributed over serveral classes then the order is definied by the spec (see my post above).
|
 |
 |
|
|
subject: Many @PostConstruct methods?
|
|
|