<Context> <Resource name="BeanManager" auth="Container" type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory" /> </Context>
For GateIn users using Tomcat which does as being a barebones JSP/Servlet container. You’d need to install a CDI implementation which does support working under Tomcat.
In this documentation, we will guide to install Weld - a CDI reference implementation, as Weld documentation is pretty clear and easy to install under Tomcat.
Perform the following steps:
This is an uber JAR of Weld itself, contains both API and Impl. At the time of writing, weld-servlet 1.1.8.Final version is being used.
<Context> <Resource name="BeanManager" auth="Container" type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory" /> </Context>
This will register Weld's BeanManager factory in Tomcat's JNDI.
<listener> <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> </listener> <resource-env-ref> <resource-env-ref-name>BeanManager</resource-env-ref-name> <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type> </resource-env-ref>
The listener entry basically enables Weld in webapp. The resource entry basically tells webapp to use the BeanManager as available in JNDI.
As you know, GateIn has provided two Portlet CDI scope annotations @PortletLifecycleScoped and @PortletRedisplayScoped which support the complex Portlet Lifecycle within CDI. BUT if you want to have them work under Tomcat, you need to add the following listener org.gatein.cdi.contexts.listeners.TomcatCDIServletListener to webapp's /WEB-INF/web.xml