[cdi-dev] BeanManager visiblity and container archives

arjan tijms arjan.tijms at gmail.com
Thu May 19 13:10:26 EDT 2016


Hi,

Thanks for the writeup!

A couple of things spring to mind. One thing is to clarify which version of
the bean manager @Inject, CDI.current() and a JNDI lookup should get/use.

Depending on the outcome of that, maybe it's useful to define several
constants and/or JNDI entries to more specifically define which bean
manager should be used.

E.g.

CDI.current(CONTAINER) // Only sees beans in the container archive
CDI.current(APPLICATION) // Only sees beans in the application archive
CDI.current(CONTAINER, APPLICATION) // beans in container and application
etc

In an EAR there are even some more options, but EARS and CDI are already
problematic, so maybe not go there just yet.

Similar variations may be used for JNDI lookups:

initialContext.lookup("java:comp/BeanManagers/container")
initialContext.lookup("java:comp/BeanManagers/application")
initialContext.lookup("java:comp/BeanManagers/container_application")

Not sure if this is the best way forward, but just throwing the idea out
there.

Kind regards,
Arjan Tijms









On Thu, May 19, 2016 at 6:47 PM, Christian Kaltepoth <christian at kaltepoth.de
> wrote:

> Hey all,
>
> I would like to bring up an issue that we ran into while preparing Ozark
> (the MVC 1.0 RI) to be usable as a container module in Glassfish. We
> discussed this issue on Slack and discovered that Mojarra (JSF) and Soteria
> (Security) had similar issues.
>
> MVC 1.0 defines some extension points that users and 3rd party libraries
> can implement to provide additional functionality. MVC uses CDI for looking
> up all implementations of these extension point interfaces. Similar
> concepts are used in in JSF. Historically JSF uses factories which users
> can implement and register via faces-config.xml. Now for Java EE 8 it was
> decided to prefer CDI to obtain such custom extension point implementations
> (ViewHandler, NavigationHandler, etc). So basically JSF uses a similar
> mechanism to lookup implementations of certain interfaces like MVC does.
>
> As of today Ozark is basically a standard bean archive deployed together
> with the application (in /WEB-INF/lib). Now we want to prepare Ozark to be
> usable as a Glassfish module which is provided by the container. As CDI
> doesn't discover bean archives installed as part of the container, we
> wanted to basically remove beans.xml and provide an portable extension
> which registers the required annotated types required for Ozark. AFAIK
> Mojarra and Soteria are also doing it this way. Now as soon as we do this,
> things are getting weird.
>
> There are various ways to get a BeanManager to lookup beans provided by
> the application:
>
>    - CDI.current().getBeanManager()
>    - @Inject BeanManager
>    - JNDI lookup
>
> Now if we try to lookup beans deployed with the application (in
> /WEB-INF/classes or in a library in /WEB-INF/lib) we don't get consistent
> results (many thanks to Arjan Tijms for doing all the testing):
>
>    - In Glassfish we don't see application beans if we use the injected
>    BeanManager. Looking up the BeanManager via JNDI or using
>    CDI.current().getBeanManager() works fine.
>    - In Wildfly CDi.current() doesn't seem to find beans deployed with
>    the application. The injected BeanManager and the one looked up via JNDI
>    works fine.
>
> So it looks like there are quite some inconsistencies between
> implementations here.
>
> *To sum it up:* In Java EE 8 more and more specs rely heavily on CDI. And
> many specs allow the user and 3rd party libraries to implement interfaces
> to extend functionality. But it looks like looking up such beans deployed
> with the application from a container archive isn't working in a consistent
> way.
>
> I hope my explanation of this complicated topic isn't too bad. I hope that
> we can start some discussion around this. Some of you already joined the
> discussion on Slack and the corresponding pull request, but I would prefer
> to discuss this here. :)
>
> Christian
>
>
> --
> Christian Kaltepoth
> Blog: http://blog.kaltepoth.de/
> Twitter: http://twitter.com/chkal
> GitHub: https://github.com/chkal
>
>
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
> Note that for all code provided on this list, the provider licenses the
> code under the Apache License, Version 2 (
> http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas
> provided on this list, the provider waives all patent and other
> intellectual property rights inherent in such information.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20160519/ffc43e4e/attachment.html 


More information about the cdi-dev mailing list