(由https://issues.jboss.org/projects/SWARM/issues/SWARM-767引用)
我正在尝试使用 Arquillian 测试我的 WildFly Swarm 应用程序。我有一个Main
用于 Swarm 的自定义类和一个自定义部署。当我尝试运行我的测试时,我收到了来自 maven 的一些第三方库的 ClassNotFoundException。
首先,这是我的测试:
@RunWith(Arquillian.class)
public class PasswordStorageTest {
@CreateSwarm
public static Swarm createSwarm() {
return TestBuilder.createSwarm();
}
@Deployment
public static WARArchive createDeployment() {
return TestBuilder.createDeployment();
}
@Test
public void testHashesAreUnique() throws PasswordStorage.CannotPerformOperationException {
String password = UUID.randomUUID().toString();
String hash1 = PasswordStorage.createHash(password);
String hash2 = PasswordStorage.createHash(password);
assertNotEquals("Hashes were not unique.", hash1, hash2);
}
@Test
public void testVerifyPassword() throws PasswordStorage.CannotPerformOperationException, PasswordStorage.InvalidHashException {
String password = UUID.randomUUID().toString();
String hash = PasswordStorage.createHash(password);
assertTrue("Password verification failed.", PasswordStorage.verifyPassword(password, hash));
}
}
TestBuilder.createSwarm()
并TestBuilder.createDeployment()
简单地分别调用这些方法:
public static Swarm buildSwarm() throws Exception {
Swarm swarm = new Swarm();
//Configure PostgreSQLDS
swarm.fraction(new DatasourcesFraction()
.jdbcDriver("org.postgresql", (d) -> {
d.driverClassName("org.postgresql.Driver");
d.xaDatasourceClass("org.postgresql.xa.PGXADataSource");
d.driverModuleName("org.postgresql");
})
.dataSource("PostgreSQLDS", (ds) -> {
ds.driverName("org.postgresql");
ds.connectionUrl(System.getenv("JDBC_DATABASE_URL"));
ds.userName(System.getenv("JDBC_DATABASE_USERNAME"));
ds.password(System.getenv("JDBC_DATABASE_PASSWORD"));
})
);
//Enable Infinispan Caching
swarm.fraction(InfinispanFraction.createDefaultFraction());
//Set Default Datasource
swarm.fraction(new JPAFraction()
.defaultDatasource("java:jboss/datasources/PostgreSQLDS"));
return swarm;
}
public static WARArchive buildDeployment() throws Exception {
WARArchive deployment = ShrinkWrap.create(WARArchive.class);
deployment.addModule("org.postgresql");
//Add all classes
deployment.addPackages(true, "com.example.myapp");
//Add all resources
recursiveAddAsClassesResource(deployment, RESOURCES);
//Add all web files
recursiveAddAsWebResource(deployment, WEB);
//Add all Maven dependencies
deployment.addAllDependencies();
return deployment;
}
当我运行测试时,WildFly Swarm 启动得很好,但是一旦部署部署,我就会收到以下错误:
2016-10-10 18:31:03,841 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."a0fdd090-cd55-4063-be86-23f6331f73f0.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."a0fdd090-cd55-4063-be86-23f6331f73f0.war".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment "a0fdd090-cd55-4063-be86-23f6331f73f0.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class com.example.myapp.core.domain.services.FileService with ClassLoader ModuleClassLoader for Module "deployment.a0fdd090-cd55-4063-be86-23f6331f73f0.war:main" from Service Module Loader
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70)
at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:57)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:106)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:91)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:76)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)
... 5 more
Caused by: java.lang.NoClassDefFoundError: net/coobird/thumbnailator/geometry/Position
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:72)
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)
... 10 more
Caused by: java.lang.ClassNotFoundException: net.coobird.thumbnailator.geometry.Position from [Module "deployment.a0fdd090-cd55-4063-be86-23f6331f73f0.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
... 15 more
我删除了引用的代码,net/coobird/thumbnailator/geometry/Position
然后在使用不同的库时遇到了类似的错误。似乎这些库根本不包括在内。
可能相关,我还在部署开始时收到大量这些消息:(但是,即使在正常运行应用程序时它们也会出现,并且由于应用程序加载得很好,因此不会引起任何问题)
WFLYSRV0059: Class Path entry file:/C:/Users/mitch/.m2/repository/net/coobird/thumbnailator/0.4.8/thumbnailator-0.4.8.jar in /C:/a0fdd090-cd55-4063-be86-23f6331f73f0.war/WEB-INF/lib/classpath.jar does not point to a valid jar for a Class-Path reference.
WFLYSRV0059: Class Path entry file:/C:/Users/mitch/.m2/repository/com/sparkpost/sparkpost-lib/0.16.1/sparkpost-lib-0.16.1.jar in /C:/a0fdd090-cd55-4063-be86-23f6331f73f0.war/WEB-INF/lib/classpath.jar does not point to a valid jar for a Class-Path reference.
这让我很困惑,特别是因为如果我设置testable = false
为@Deployment
,那么它运行得非常好;但是,由于测试现在在容器外运行,我不能使用我需要的 CDI 注入。
我可以提供更多需要的信息。我不知道从这里去哪里。