diff --git a/jetty-cdi/pom.xml b/jetty-cdi/pom.xml index 5f5073cdec1..102592e6816 100644 --- a/jetty-cdi/pom.xml +++ b/jetty-cdi/pom.xml @@ -35,6 +35,11 @@ + + org.eclipse.jetty + jetty-plus + ${project.version} + org.eclipse.jetty jetty-deploy diff --git a/jetty-cdi/src/main/config/modules/cdi.mod b/jetty-cdi/src/main/config/modules/cdi.mod index b66263eb43e..68dea58b627 100644 --- a/jetty-cdi/src/main/config/modules/cdi.mod +++ b/jetty-cdi/src/main/config/modules/cdi.mod @@ -5,6 +5,7 @@ [depend] deploy annotations +plus # JSP (and EL) are requirements for CDI and Weld jsp diff --git a/jetty-cdi/src/main/java/org/eclipse/jetty/cdi/WeldDeploymentBinding.java b/jetty-cdi/src/main/java/org/eclipse/jetty/cdi/WeldDeploymentBinding.java index ba43c7b89c2..24cee5ff3dd 100644 --- a/jetty-cdi/src/main/java/org/eclipse/jetty/cdi/WeldDeploymentBinding.java +++ b/jetty-cdi/src/main/java/org/eclipse/jetty/cdi/WeldDeploymentBinding.java @@ -18,10 +18,15 @@ package org.eclipse.jetty.cdi; +import javax.naming.Reference; + import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.AppLifeCycle; import org.eclipse.jetty.deploy.graph.Node; +import org.eclipse.jetty.plus.jndi.Resource; import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.WebAppContext; /** @@ -29,6 +34,8 @@ import org.eclipse.jetty.webapp.WebAppContext; */ public class WeldDeploymentBinding implements AppLifeCycle.Binding { + private static final Logger LOG = Log.getLogger(WeldDeploymentBinding.class); + public String[] getBindingTargets() { return new String[] @@ -47,12 +54,23 @@ public class WeldDeploymentBinding implements AppLifeCycle.Binding { WebAppContext webapp = (WebAppContext)handler; + if (!wantsCDI(webapp)) + { + LOG.info("No CDI features discovered, not adding Weld to context: {}",webapp); + return; + } + // Add context specific weld container reference. // See https://issues.jboss.org/browse/WELD-1710 // and https://github.com/weld/core/blob/2.2.5.Final/environments/servlet/core/src/main/java/org/jboss/weld/environment/servlet/WeldServletLifecycle.java#L244-L253 webapp.setInitParameter("org.jboss.weld.environment.container.class", "org.jboss.weld.environment.jetty.JettyContainer"); + // Setup Weld BeanManager reference + Reference ref = new Reference("javax.enterprise.inject.spi.BeanManager", + "org.jboss.weld.resources.ManagerObjectFactory", null); + new Resource(webapp,"BeanManager",ref); + // webapp cannot change / replace weld classes webapp.addSystemClass("org.jboss.weld."); webapp.addSystemClass("org.jboss.classfilewriter."); @@ -66,4 +84,10 @@ public class WeldDeploymentBinding implements AppLifeCycle.Binding webapp.addServerClass("-com.google.common."); } } + + private boolean wantsCDI(WebAppContext webapp) + { + // TODO implement search for various "bean.xml" entries. + return true; + } } diff --git a/tests/test-cdi/cdi-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/test-cdi/cdi-webapp/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/test-cdi/cdi-webapp/src/main/webapp/WEB-INF/web.xml b/tests/test-cdi/cdi-webapp/src/main/webapp/WEB-INF/web.xml index 292a1677caf..fe2940c4f8d 100644 --- a/tests/test-cdi/cdi-webapp/src/main/webapp/WEB-INF/web.xml +++ b/tests/test-cdi/cdi-webapp/src/main/webapp/WEB-INF/web.xml @@ -4,4 +4,15 @@ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> CDI Integration Test WebApp + + + org.jboss.weld.environment.servlet.Listener + + + + Object factory for the CDI Bean Manager + BeanManager + javax.enterprise.inject.spi.BeanManager + +