[cdi-dev] @PostConstruct and @Inject methods in superclasses
Mark Struberg
struberg at yahoo.de
Fri Sep 30 15:47:18 EDT 2011
Hi!
JSR-250 common annotations is pretty thin about having @PostConstruct in multiple class hierarchies. It just says that there must only be one single method annotated with @PostConstruct in a class. Thus my question:
If I have
public class Animal {
@PostConstruct
public void doInit() {..}
..
}
and
public class Horse extends Animal {
@PostConstruct
public void doSomeOtherInit() {..}
..
}
1.) for a contextual instance of Horse, will Animal#doInit() get executed or only the one from the 'effective' class?
2.) if 1.) was yes, then In which order do they get executed? Is this specced somewhere?
3.) Same scenario with @Inject methods. Do we specify an order?
4.) Both classes have @Inject methods and @PostConstruct. Again: which order of invocaition?
Just that you understand my intention: we had a @PostConstruct method in Horse which did set a 'cached' flag in Animal. Turned out that this was a random generator depending on the intsalled server ;)
LieGrue,
strub
More information about the cdi-dev
mailing list