For DropWizard 0.8.1 and Weld 2.2, the procedure is as follows:
1) Add the dependencies to pom.xml:
<dependency> <groupId>org.jboss.weld.servlet</groupId> <artifactId>weld-servlet-core</artifactId> <version>2.2.11.Final</version> </dependency> <dependency> <groupId>org.glassfish.jersey.ext.cdi</groupId> <artifactId>jersey-cdi1x</artifactId> <version>2.17</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
2) Add the beans.xml file to src / main / resources / META-INF and add an inclusion filter for application packages. This is especially necessary when using a shaded can - without a filter, Weld scans each class in a shaded can.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:weld="http://jboss.org/schema/weld/beans"> <weld:scan> <weld:include name="com.example.**" /> </weld:scan> </beans>
3) Register Weld listener in application class
@Override public void run(Configuration conf, Environment env) throws Exception { env.servlets().addServletListeners(new org.jboss.weld.environment.servlet.Listener()); }
source share