-
1. Re: CDI Extension, @Inject and Interceptors
vladcrc Oct 25, 2012 12:08 PM (in response to veitg)Hi,
I am also having the problem that Interceptors don't work in an extension.
https://community.jboss.org/message/765016
And coulnd't find an answer...
-
2. Re: CDI Extension, @Inject and Interceptors
codeprince Oct 25, 2012 9:21 PM (in response to veitg)Hi Veit,
Veit Guna による書き込み:
Hi.
I'm using JBoss 7.1.1 Final and currently implementing a CDI Extension. During development I encountered some caveats that I couldn't find in any documentation and cost me some time to figure out.
1) @Inject for Event<T> and BeanManager (or in general?) doesn't seem to work in Extensions - they're always null. I found out somewhere that you can let inject them as a 2nd parameter in a Observer method.
BeanManager can be obtained as 2nd parameter as following:
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bdd, BeanManager beanManager){
...
this.beanManager = beanManager;
}
-
3. Re: CDI Extension, @Inject and Interceptors
jharting Oct 26, 2012 4:19 AM (in response to codeprince)CDI extensions are not managed beans and thus are not provided with CDI services. The only thing you can inject is the BeanManager as shown above. However, you should not use it to lookup beans, decorators, etc. until the container is initialized.
-
4. Re: CDI Extension, @Inject and Interceptors
alberto_souza Dec 18, 2012 8:28 AM (in response to jharting)I am not so sure about that. The AfterDeploymentValidation observer can receive managed objects, at least in my tests. I don't know if this is a weld feature or a spec feature.
-
5. Re: CDI Extension, @Inject and Interceptors
jharting Dec 20, 2012 3:16 AM (in response to alberto_souza)That is an unspecified feature which applications should not rely on. It is going to be removed.
-
6. Re: CDI Extension, @Inject and Interceptors
codeprince Dec 20, 2012 8:18 PM (in response to jharting)Jozef Hartinger による書き込み:
That is an unspecified feature which applications should not rely on. It is going to be removed.
Hi Jozef,
What you said "It is going to be removed" is that in the future, beanManager can not be obtained from beforeBeanDiscovery method?
In addition, just as you said, beanManager from beforeBeanDiscovery method is a extension beanManager, and there is a possibility that a user can not
use the beanManager to lookup managed beans(or some beans related user-defined classes) , of course , this also depends on how deployment.loadBeanDeploymentArchive(Class<?> beanClass)
is implemented?
I have found a scene on glassfish weld integration: if you obtain a beanManager from beforeBeanDiscovery method which is in glassfish cdi extension, you can not look up managed beans because the
extension deployment's beanDeploymentArchive has not visibility to managed beans.
Thanks
--Tang
-
7. Re: CDI Extension, @Inject and Interceptors
jharting Dec 21, 2012 8:03 AM (in response to codeprince)No, the possibility of injecting other instances to container lifecycle event observers is non-portable going to be removed. BeanManager will still be injectable though certain methods will not be allowed to be called during container initialization. See https://issues.jboss.org/browse/CDI-274 for details.