-
1. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
thomasgo Feb 14, 2012 11:35 AM (in response to stepanov)I have the same problem under JBoss 7.1.0.CR1b.
Did you find out something yet?
It also seems not to be a singleton specific problem.
I created another bean which is injected into the singleton and invoked in the @PostConstruct annotated method of that singleton.
InjectionTarget.inject() is called on both, but InjectionTarget.postConstruct() is not.
-
2. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
stepanov Feb 21, 2012 3:28 PM (in response to thomasgo)I didn't have much time for digging of Weld sources and reverted to using inject() method. However, this method is called every time the target is being injected thus for singletons you have to devise a safe guard code suitable for your case.
Meanwhile, can anybody from JBoss Weld confirm if this is a bug or just our misunderstanding of core CDI concepts?
-
3. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
alesj Feb 21, 2012 3:43 PM (in response to stepanov)Meanwhile, can anybody from JBoss Weld confirm if this is a bug or just our misunderstanding of core CDI concepts?
It looks like a bug; Stuart can say this for sure.
Could you perhaps create an ARQ test in Weld-Core with this example?
-
4. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
alesj Feb 21, 2012 3:49 PM (in response to alesj)Could you perhaps create an ARQ test in Weld-Core with this example?
And of course create a pull-request from it. :-)
-
5. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
stepanov Feb 21, 2012 4:01 PM (in response to alesj)Errr... I'm not quite familiar with your development cycle procedures (proper test locations, "pull-request" concept, responsible contacts etc) but if you give me some directions... More of that, I don't have much of expirience with Arquillian
-
6. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
pmuir Feb 21, 2012 4:20 PM (in response to stepanov)The issue here is that the responsibility for calling the @PostConstruct method on the EJB is not necessarily the responsibility of CDI (the EJB container also defines @PostConstruct) so your metadata adjustment, which only affects CDI, has no effect.
If you were trying to do this with a CDI managed bean, it should work.
It's not necessarily a bug, but it could be improved on. Stuart, is there a way to have CDI process @PostConstruct and @PreDestroy for EJBs on AS7?
We are trying to align this better for Java EE 7, however it is tricky :-(
-
7. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
alesj Feb 21, 2012 4:21 PM (in response to stepanov)Errr...
:-)
Check other tests in that directory, I think you'll quickly see that it's super easy to add a new test.
* proper test location --> i would expect there are other @Singleton tests there, if not, add where you best think it fits; we can always easily move it
* "pull-request" --> that's a GitHub notion; something one should definitely learn == super useful in OSS work ;-)
* responsible contact --> there is no such thing in OSS; I either accept your patch or I don't; once I do, it's my responsibility
* Arquillian --> it's all already setup; besides that, all ARQ experience can be described with few annotations = @Arquillian, @Deployment, @Test
-
8. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
alesj Feb 21, 2012 4:24 PM (in response to pmuir)It's not necessarily a bug, but it could be improved on. Stuart, is there a way to have CDI process @PostConstruct and @PreDestroy for EJBs on AS7?
I think this could be a part of the custom interceptors we already add for scope, passivation, etc handling.
e.g. fire InstanceTarget::postConstruct in that interceptor when EJBs @PostConstruct is invoked
-
9. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
swd847 Feb 21, 2012 6:14 PM (in response to stepanov)https://issues.jboss.org/browse/AS7-3859
I think I should be able to fix it for AS7, but I have not looked into what would be involved yet.
-
10. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
swd847 Feb 21, 2012 6:49 PM (in response to swd847)Actually it looks like this may require SPI changes in weld, if I change the AS7 code to simply delegate to CDI it will break other things, as CDI does not have enough information to build up the correct EJB interceptor information (e.g. it does not know about interceptor methods defined in ejb-jar.xml)
-
11. Re: CDI Extension with Singleton EJB: InjectionTarget.postConstruct() is not called
stepanov Feb 21, 2012 6:59 PM (in response to swd847)So basically it all comes down to the single question: why doesn't JBoss AS 7 use CDI (and Weld) for processing of all EJB annotations... Wouldn't it make life easier for both teams? Instead you have CDI for web-container part and JBoss deployers for EJBs, although to my understanding it is possible to write CDI extensions for handling all of them.
Update: oh, I see.. there are xml descriptors in EJB spec, not only annotations.