[wildfly-dev] Wrong beanmanager retrieved by CDI.current().getBeanManager() in Struts1

Eric B ebenzacar at gmail.com
Thu Jan 4 14:05:17 EST 2018


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:
EAR
 - root.war
 - ejb.jar
 - web.war
 - ws.war
 - lib/common jars


In one of my war1 web filters, I am sucessfully able to retrieve a bean
from the CDI using:
         SessionManager sessionManager =
CDI.current().select(SessionManager.class).get()

However, in a Struts1 action, I'm trying to retrieve the same bean from the
CDI using:
         SessionManager sessionManager =
CDI.current().select(SessionManager.class).get()

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:
- ear/root.war
- ear/ws.war
- ear/ejb.jar
- ear/web.war

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");
Set<Bean<?>> beans = beanManager.getBeans(SessionManager.class);
Bean<?> bean = beanManager.resolve(beans);
CreationalContext<?> context = beanManager.createCreationalContext(bean);
SessionManager sessionManager = (SessionManager)
beanManager.getReference(bean, SessionManager.class, context);




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?

Struts1 is launched as a servlet in the web.xml:
   <servlet>
      <servlet-name>action</servlet-name>
      <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
      <init-param>
         <param-name>config</param-name>
         <param-value>/WEB-INF/struts-config.xml</param-value>
      </init-param>
      <init-param>
         <param-name>chainConfig</param-name>
         <param-value>/WEB-INF/chain-config.xml</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
   </servlet>



Thanks!

Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/wildfly-dev/attachments/20180104/0efc9fe3/attachment.html 


More information about the wildfly-dev mailing list