我試圖在我的Web項目中使用Jboss Seam 2,Hibernate/JPa等設置Arquillian。我更新了我的pom.xml將下面的代碼和平:Arquillian,Tomcat和Jboss Seam 2
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.jboss.arquillian/arquillian-bom -->
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.13.Final</version>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
...
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>7.0.42</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.42</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>7.0.42</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>3.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-7</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.shrinkwrap.resolver/shrinkwrap-resolver-impl-maven -->
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>2.2.6</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.arquillian.junit/arquillian-junit-container -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.1.13.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
因此,在第二步驟之後加入我的pom.xml依賴創建一個測試的Arquillian類,見:
package com.projectx;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.annotations.In;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.projectx.MyService;
@RunWith(Arquillian.class)
public class MyServiceTest {
@Deployment
public static JavaArchive createTestArchive() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class).addPackages(true, "com.projectx");
return jar;
}
@In
private MyService myService;
@Test
public void validateValue() {
ReturnBean returnBean = myService.validateNow(null);
}
}
最後我嘗試運行我的測試類,我指出,「爲myService」對象爲空,在注入點沒有工作,所以我就NullPointerException異常。
我的照片是我沒有在ShrinkWrap中插入JavaArchive所需的所有東西。無論如何,無論如何,創建我的arquillian與maven創建的戰爭?
編輯1: 添加以下的依賴在我的pom.xml:
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-seam2</artifactId>
<version>1.0.0.Beta1</version>
</dependency>
而且改變了這種依賴關係波紋管的版本,因爲保持兼容使用的Arquillian-seam2:
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.1.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.1.Final</version>
<type>pom</type>
</dependency>
但是當我試圖開始測試時,我得到以下錯誤:
GRAVE: Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
java.lang.IllegalStateException: duplicate factory for: org.jboss.seam.web.webSession (duplicate is specified in components.xml)
at org.jboss.seam.core.Init.checkDuplicateFactoryExpressions(Init.java:227)
at org.jboss.seam.core.Init.checkDuplicateFactory(Init.java:220)
at org.jboss.seam.core.Init.addFactoryValueExpression(Init.java:283)
at org.jboss.seam.init.Initialization.installComponents(Initialization.java:1152)
at org.jboss.seam.init.Initialization.init(Initialization.java:737)
at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1653)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
解決方案: 我將我的容器從apache-tomcat更改爲jboss-as-5.1。
我會測試並返回這裏,謝謝。 – RonaldoLanhellas
我推出了arquillian-seam2擴展,但是我在編輯帖子中報告了錯誤。你可以幫我嗎 ? – RonaldoLanhellas
當然,但理想情況下,我需要一個小型複製器項目。你能準備這樣的事情,並通過GitHub分享? –