Arquillian failing with duplicate CDI bean errors, tomcat-embedded-7 + WELD 2.2.10.Final
chrisjr Apr 15, 2015 7:39 PMHi,
I have created a WAR file containing WELD 2.2.10.Final that deploys into Tomcat 7, and I am trying to integration test it using Arquillian 2.1.1. For the most part, this @Deployment is working:
public class Deployments {
private static final File WEBAPP_SRC = new File("src/main/webapp");
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class, "ROOT.war")
.addAsLibraries(Maven.resolver().loadPomFromFile("pom.xml").importRuntimeDependencies().resolve().withTransitivity().asFile())
.addPackages(true, Filters.exclude(".*Test.*|.*/Arquillian.*|.*/Dummy.*"), "com.my.packages")
.deleteClass(Deployments.class)
.addAsManifestResource(new File(WEBAPP_SRC, "META-INF/context.xml"), "context.xml")
.addAsWebInfResource(new File(WEBAPP_SRC, "WEB-INF/beans.xml"))
.setWebXML(new File(WEBAPP_SRC, "WEB-INF/web.xml"))
.setManifest("dummy-manifest.mf");
}
}
ShrinkWrap creates a ROOT.war, which Arquillian successfully deploys into an embedded Tomcat container. The only issue so far has been these warnings in the Tomcat logs, which I have been ignoring up to now:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/Users/crankin/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/workspace/proggy/proggy-server/proggy-server-web/target/tomcat7-embedded/webapps/ROOT/WEB-INF/lib/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
(BTW, my container definition contains the line <property name="tomcatHome">target/tomcat7-embedded</property>).
My problem now is that I've just included a dependency into my WAR for a JAR file that contains both a CDI bean and a beans.xml file. And suddenly WELD is crashing and burning inside the embedded Tomcat because it claims that my application contains two copies of my library CDI bean! However, I've examined the ROOT.war that ShrinkWrap creates, and it's fine. (It even boots and runs correctly when deployed into a standalone Tomcat 7).
My guess is that Arquillian / ShrinkWrap is doing that same thing with my library JAR as it already has with logback-classic-1.1.2.jar (and presumably every other JAR in ROOT.war) and adding the artifact from the local Maven repository to the classpath as well. And I'm stumped - I cannot find any way of telling Arquillian / ShrinkWrap just to deploy ROOT.war, and to forget about the local repository once ROOT.war has been created.
Does anyone have any suggestions please? Could this be a bug in Arquillian and/or ShrinkWrap? And if not, then what am I doing wrong?
Thanks for any help,
Chris Rankin