Wrong beanmanager retrieved by CDI.current().getBeanManager() in Struts1
I'm running into a really strange behaviour, and I'm not entirely sure where/how to start looking for this or if it is something that I can easily reproduce in a test case (or if it is even worthwhile).
I've got a mutil-war JEE EAR application that uses EJBs, Struts1. and Struts2.
My EAR is as follows:
- lib/common jars
In one of my war1 web filters, I am sucessfully able to retrieve a bean from the CDI using:
but WELD throws and error that it is unable to resolve the SessionManager bean:
org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308: Unable to resolve any beans for Type: interface webapp.session.SessionManager; Qualifiers: 
When I dig more into it, I see that CDI.current().getBeanManager() in the filter always returns the beanManager for my ear/web.war deployment. However, when trying the same call in my Struts 1 Action, instead, it will at times retrieve the bean manager for other deployments, seemingly randomly:
If I retrieve the BeanManager manually from the JNDI, using a JNDI lookup, I am able to retrieve the bean without problems:
BeanManager beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
So at the end, I'm not entirely sure why CDI.current().getBeanManager() would be retrieving the BeanManager from a different context. Might this be a bug in Weld, a problem in the container, or something strange that is happening due to the way that Struts1 was designed? Or do I need to do/add something specific to a config to enable CDI access from within a servlet?
Re: Wrong beanmanager retrieved by CDI.current().getBeanManager() in Struts1
On 05/01/18 12:35 AM, Eric B wrote:
> However, when trying the same call in my Struts 1 Action, instead, it
> will at times retrieve the bean manager for other deployments,
> seemingly randomly:
If it's returning it in a non-deterministic manner then it does sound
like a bug. Is this an application you can share?
P.S: The WildFly user forums https://developer.jboss.org/en/wildfly is a
better place for such questions and the forum infrastructure even allows
you to attach files, unlike this mailing list IIRC.