-
1. Re: @PostConstruct method not called on CDI bean from external deployment module
manovotn Sep 21, 2017 4:20 AM (in response to per.norrman)Hi Petr,
what you describe is somewhat grey area which may or may not work as you think/expect.
Have you tried using initializer method instead of `@PostConstruct` call? Should do the job done for you and might just work in external module.
Myself, I'll have to find out more about external modules to investigate this - if you could attach sources/reproducer, that would be great.
-
2. Re: @PostConstruct method not called on CDI bean from external deployment module
per.norrman Sep 21, 2017 5:03 AM (in response to manovotn)Hi Matej,
thanks for the reply. I will have a look at initializer method. In the meantime, I attach a gitbundle of the minimal reproducer.
Cheers,
Per
-
3. Re: @PostConstruct method not called on CDI bean from external deployment module
per.norrman Sep 25, 2017 9:00 AM (in response to manovotn)Hi Matej,
Injection method solved the problem, or maybe it should be viewed as a workaround, since I'm not dependent on an orderly shutdown through @PreDestroy. However, it would still be of value to understand why it happens. I can clearly see from trace logging that CDI is populating the client proxy object with post construct method interceptors.
Cheers,
Per
-
4. Re: @PostConstruct method not called on CDI bean from external deployment module
manovotn Sep 26, 2017 6:53 AM (in response to per.norrman)Alright, so after some investigation (most credits go to mkouba), we found the issue.
In your module.xml, you want to add a dependency on
<module name="javax.annotation.api"/>
and then post construct interceptor starts working.
As it stands, if you do not add this dependency, the annotation will be ignored.
Normally, if you miss a dependency in module.xml, it would blow up, but it looks like there is some tweak (making it look intended) for annotations where it ignores the missing pieces.
As a consequence, when Weld attempts to grab this class and turn it into proxy, it no longer sees the annotation hence cannot do post construct properly.
EDIT: Actually this behaviour seems to be expected as it is defined by JVM - when you miss the class on CP at runtime, the program will still execute and ignore the annotations.
It had been explained in this SO question (and by extension in the JLS).