Tweaking WeldDeploymentBinding for more accurate weld setup
This commit is contained in:
parent
cba0ce2b9e
commit
b478d49062
|
@ -35,6 +35,11 @@
|
|||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-plus</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-deploy</artifactId>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
[depend]
|
||||
deploy
|
||||
annotations
|
||||
plus
|
||||
# JSP (and EL) are requirements for CDI and Weld
|
||||
jsp
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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">
|
||||
<display-name>CDI Integration Test WebApp</display-name>
|
||||
|
||||
<listener>
|
||||
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
|
||||
</listener>
|
||||
|
||||
<resource-env-ref>
|
||||
<description>Object factory for the CDI Bean Manager</description>
|
||||
<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>
|
||||
|
||||
</web-app>
|
||||
|
|
Loading…
Reference in New Issue