users@glassfish.java.net

Injecting BeanManager into CDI portable extension: possible, or GF bug?

From: <glassfish_at_javadesktop.org>
Date: Mon, 12 Jul 2010 10:35:16 PDT

My detailed post on this issue is cross-posted to the Weld-users group: http://seamframework.org/Community/CorrectWayToInjectBeanManagerIntoPortableExtension

Briefly: I have a CDI portable extension which Glassfish is properly recognizing. However, I cannot seem to get a BeanManager injected into it. The CDI specification seems--seems--to indicate that this should be possible, though it is kind of a gray area: it is not clear (to me) whether a portable extension, loaded via the META-INF/services mechanism, is a CDI bean and hence subject to full CDI injection rules.

So: should I be able to inject a BeanManager into my CDI portable extension? If so, how?

This doesn't work, and no error is generated:

[code]
@Inject
private BeanManager beanManager;
[/code]

...and this doesn't work either:

[code]
@Inject
public void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanManager beanManager) {
  //...
}
[/code]

...because I get the following error:

[code]
WELD-000408 org.jboss.weld.event-ObserverMethod-com.foobar.MyPortableExtension.method afterDeploymentValidation(javax.enterprise.inject.spi.AfterDeploymentValidation, javax.enterprise.inject.spi.BeanManager) cannot be annotated with @Initializer
[/code]

Pilot error, spec impossibility, or Glassfish bug?

Thanks,
Laird
[Message sent by forum member 'ljnelson']

http://forums.java.net/jive/thread.jspa?messageID=477368