我在Arquillian的EJB中创建了一些测试。迄今已通过2次测试。不幸的是,第三次测试失败了我难以跟踪的奇怪信息。
13:16:51,206 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.unit."test4.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."test4.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "test4.jar"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_76]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_76]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_76]
Caused by: java.lang.RuntimeException: Error getting reflective information for class com.group7.service.NetworkService with ClassLoader ModuleClassLoader for Module "deployment.test4.jar:main" from Service Module Loader
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:58)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:85)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:70)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:55)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more
Caused by: java.lang.NoClassDefFoundError: Lcom/group7/daoInterface/NetworkDAOLocal;
at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.7.0_76]
at java.lang.Class.privateGetDeclaredFields(Class.java:2499) [rt.jar:1.7.0_76]
at java.lang.Class.getDeclaredFields(Class.java:1811) [rt.jar:1.7.0_76]
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 10 more
Caused by: java.lang.ClassNotFoundException: com.group7.daoInterface.NetworkDAOLocal from [Module "deployment.test4.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
... 15 more
13:16:51,220 INFO [org.jboss.as.server] (management-handler-thread - 3) JBAS015870: Deploy of deployment "test4.jar" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"test4.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"test4.jar\".POST_MODULE: Failed to process phase POST_MODULE of deployment \"test4.jar\""}}
13:16:51,228 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment test4.jar in 7ms
13:16:51,229 INFO [org.jboss.as.controller] (management-handler-thread - 3) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.deployment.unit."test4.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."test4.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "test4.jar"
13:16:51,281 INFO [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015877: Stopped deployment arquillian-service in 6ms
13:16:51,306 INFO [org.jboss.as.repository] (management-handler-thread - 1) JBAS014901: Content removed from location /home/bmj/Java/jboss_7.1/standalone/data/content/f0/d4d08224b3f1a188bb5d596eec8a15b971ec45/content
13:16:51,307 INFO [org.jboss.as.server] (management-handler-thread - 1) JBAS018558: Undeployed "arquillian-service"
我不知道我做错了什么。正如我所说,我之前的2次测试没有任何问题。
NetworkServiceEJBTest.java
package com.group7.service;
import static org.junit.Assert.*;
import javax.ejb.EJB;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.group7.daoInterface.NetworkDAOLocal;
import com.group7.entities.Network;
import com.group7.entities.NetworkId;
import com.group7.serviceInterface.NetworkServiceLocal;
@RunWith(Arquillian.class)
public class NetworkServiceEJBTest {
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class, "test4.jar")
.addClasses(Network.class, NetworkId.class, NetworkService.class, NetworkServiceLocal.class)
.addAsResource("META-INF/persistence.xml")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
@EJB
private NetworkDAOLocal dao;
@Test
public void isNetworkTableEmpty() throws Exception {
assertFalse(dao.getAllNetworkInfo().isEmpty());
// assertEquals(dao.getAllNetworkInfo().size(), 1);
}
}
Network.java (实体)
package com.group7.entities;
import java.io.Serializable;
/**
*
* @author marc
*
*/
@Entity
@IdClass(NetworkId.class)
@Table(name="Network")
public class Network implements Serializable{
@Id
@Column(name = "MCC")
private int mcc;
@Id
@Column(name = "MNC")
private int mnc;
@Column(name = "Country")
private String country;
@Column(name = "Operator")
private String operator;
//Getters and setters
public int getMcc() {
return mcc;
}
public void setMcc(int mcc) {
this.mcc = mcc;
}
public int getMnc() {
return mnc;
}
public void setMnc(int mnc) {
this.mnc = mnc;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
}
NetworkDaoImpl.java (网络dao)
package com.group7.dao;
import java.util.Collection;
@Stateless
@Local
public class NetworkDAOImple implements NetworkDAOLocal{
@PersistenceContext
private EntityManager em;
public Collection<Network> getAllNetworkInfo() {
Query q = em.createQuery("from Network");
return q.getResultList();
}
}
NetworkDAOLocal.java (dao界面)
package com.group7.daoInterface;
import java.util.Collection;
@Local
public interface NetworkDAOLocal {
Collection<Network> getAllNetworkInfo();
}
arquillian.xml
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="jbossas-managed-wildfly-8" default="true">
<configuration>
<property name="jbossHome">/home/bmj/Java/jboss_7.1</property>
</configuration>
</container>
</arquillian>
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.group7.theramones</groupId>
<artifactId>TeamProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-7.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.3.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.10</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>arquillian-jbossas-embedded</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.3.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-7.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.CR7</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>2.1.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>arquillian-jbossas-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-7.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<version>7.1.1.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
答案 0 :(得分:3)
您发布的错误非常清楚,在您的JAR中找不到NetworkDaoLocal
。即使您共享的部署也不包括它,而是包括NetworkServiceLocal