<div dir="ltr">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).<div><br></div><div>I've got a mutil-war JEE EAR application that uses EJBs, Struts1. and Struts2.</div><div><br></div><div>My EAR is as follows:</div><div>EAR</div><div> - root.war</div><div> - ejb.jar</div><div> - web.war</div><div> - ws.war</div><div> - lib/common jars<br></div><div><br></div><div><br></div><div>In one of my war1 web filters, I am sucessfully able to retrieve a bean from the CDI using:</div><div><div> SessionManager sessionManager = CDI.current().select(SessionManager.class).get()</div></div><div><br></div><div>However, in a Struts1 action, I'm trying to retrieve the same bean from the CDI using:</div><div><div> SessionManager sessionManager = CDI.current().select(SessionManager.class).get()</div></div><div><br></div><div>but WELD throws and error that it is unable to resolve the SessionManager bean:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308: Unable to resolve any beans for Type: interface webapp.session.SessionManager; Qualifiers: []</div></blockquote><div><br></div><div><br></div><div>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:</div><div>- ear/root.war</div><div>- ear/ws.war</div><div>- ear/ejb.jar</div><div>- ear/web.war</div><div><br></div><div>If I retrieve the BeanManager manually from the JNDI, using a JNDI lookup, I am able to retrieve the bean without problems:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>BeanManager beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");</div></div><div><div>Set<Bean<?>>
beans = beanManager.getBeans(SessionManager.class);</div></div><div><div>Bean<?> bean =
beanManager.resolve(beans);</div></div><div><div>CreationalContext<?> context =
beanManager.createCreationalContext(bean);</div></div><div><div>SessionManager sessionManager =
(SessionManager) beanManager.getReference(bean, SessionManager.class,
context);</div></div></blockquote><div><br></div><div><br></div><div><br></div><div>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?</div><div><br></div><div>Struts1 is launched as a servlet in the web.xml:</div><div><div> <servlet></div><div> <servlet-name>action</servlet-name></div><div> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class><br></div><div> <init-param></div><div> <param-name>config</param-name></div><div> <param-value>/WEB-INF/struts-config.xml</param-value></div><div> </init-param></div><div> <init-param><br></div><div> <param-name>chainConfig</param-name></div><div> <param-value>/WEB-INF/chain-config.xml</param-value><br></div><div> </init-param><br></div><div> <load-on-startup>1</load-on-startup></div><div> </servlet></div></div><div><br></div><div><br></div><div><br></div><div>Thanks!</div><div><br></div><div>Eric</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>