0

我正在尝试在我的项目上运行 Arquillian 测试,其中包含一个用于协议提供程序测试的 h2 数据库。

但我收到以下错误消息:

2018-10-17 14:43:15,826 错误 [org.jboss.as.controller.management-operation](ServerService 线程池 -- 28)[/] - WFLYCTL0013:操作(“添加”)失败 - 地址:([ ("subsystem" => "datasources"), ("jdbc-driver" => "h2") ]) - 故障描述:“WFLYJCA0041: 无法加载驱动程序 [com.h2database.h2] 的模块”

我的 project-defaults.yaml 包含以下内容:

datasources:
  jdbc-drivers:
    h2:
      driver-class-name: org.h2.Driver
      xa-datasource-class-name: org.h2.jdbcx.JdbcDataSource
      driver-module-name: com.h2database.h2
  data-sources:
    ExmapleDS:
      driver-name: h2
      connection-url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
      user-name: sa
      password: sa

我的 Arquillian 部署

@Deployment(testable = false)
public static WebArchive createDeployment() {
    PomEquippedResolveStage pomFile = Maven.resolver().loadPomFromFile("pom.xml");

    File[] libs = Maven.configureResolver().loadPomFromFile("pom.xml")
    .importRuntimeAndTestDependencies().resolve()
    .withTransitivity().asFile();

    WebArchive archive = ShrinkWrap.create(WebArchive.class)
    .addAsLibraries(pomFile.resolve("org.apache.commons:commons-lang3").withTransitivity().asFile())
    .addAsLibraries(pomFile.resolve("io.thorntail:datasources:2.2.0.Final").withTransitivity().asFile())
    .addAsLibraries(pomFile.resolve("com.h2database:h2:1.4.197").withTransitivity().asFile())
    .addAsLibraries(pomFile.resolve("org.assertj:assertj-core").withTransitivity().asFile())
    .addAsLibraries(libs)
    .addPackage(ShoppingCart.class.getPackage())
    .addClass(Product.class)
    .addClass(TracerResolver.class)
    .addClass(ShoppingCartOpenApiFilter.class)
    .addPackage(Persistence.class.getPackage())
    .addPackage(ShoppingCartResource.class.getPackage())
    .addAsResource("import.sql")
    .addAsWebInfResource("test-persistence.xml", "META-INF/persistence.xml")
    .addAsResource("project-defaults.yml")
    .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("META-INF/beans.xml"));

    LOG.debug(archive.toString(true));
    return archive;
}

和我的 test-persistence.xml

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
         http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
         version="2.1">
  <persistence-unit name="ExampleDS" transaction-type="JTA">
    <properties>
      <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
      <property name="javax.persistence.schema-generation.create-source" value="metadata"/>
      <property name="javax.persistence.schema-generation.drop-source" value="metadata"/>
      <property name="javax.persistence.sql-load-script-source" value="import.sql"/>
    </properties>
  </persistence-unit>
</persistence>
4

1 回答 1

0

我必须将 h2 的 module.xml 添加到 scr/main/resources/modules/com/h2database/h2/main

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2015 Red Hat, Inc. and/or its affiliates.
  ~
  ~ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
  -->
<module xmlns="urn:jboss:module:1.3" name="com.h2database.h2">

  <resources>
    <artifact name="com.h2database:${h2.version}"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
    <module name="javax.servlet.api" optional="true"/>
  </dependencies>
</module>
于 2018-10-24T11:27:35.233 回答