使用 postgresql jdbc driver 和 wildfly-arquillian-container-managed

Using postgresql jdbc driver with wildfly-arquillian-container-managed

我们使用带有嵌入式 wildfly[1] 到 运行 集成测试的 arquillian。到目前为止,我们在内存数据库中使用 H2。由于某些原因,我们需要在测试中也切换到 postgres 以更好地覆盖真实情况(在生产中,我们使用 postgres)。 我目前在部署 test.war:

期间遇到此错误
13:57:30,981 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("jdbc-driver" => "postgresql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [org.postgresql.jdbc]"

这很清楚,因为 driver 不可用。

但是如何让嵌入式 wildfly 支持 postgres jdbc driver?我习惯于将 driver 复制到已安装的 wildfly 包的模块目录中......但这在这里是不可能的......而且似乎没有我可以添加的 Maven 依赖性,它添加了 jdbc driver...

顺便说一句,添加到最后,我的目标是使用定义数据源的改编 standalone.xml(而不是使用 xxx-ds.xml 文件),因为我喜欢也可以设置其他设置。

[1]

    <dependency>
        <groupId>org.wildfly.arquillian</groupId>
        <artifactId>wildfly-arquillian-container-managed</artifactId>
    </dependency>

我设法解决了将 standalone.xml、jdbc 驱动程序和 module.xml 复制到提取的 Wildfly 中的问题。

这是我使用带有嵌入式 wildfly 的 maven 和 arquillian 的第一步。欢迎提出任何改进建议。

<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>                    
                <execution>
                    <id>unpack</id>
                    <phase>process-test-classes</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.wildfly</groupId>
                                <artifactId>wildfly-dist</artifactId>
                                <version>10.1.0.Final</version>
                                <type>zip</type>
                                <overWrite>false</overWrite>
                                <outputDirectory>target</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>                    
                <execution>
                    <id>copy-db-driver</id>
                    <phase>process-test-classes</phase>
                    <goals>
                        <goal>copy</goal> 
                   </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.postgresql</groupId>
                                <artifactId>postgresql</artifactId>
                                <version>9.4.1212</version>
                                <outputDirectory>target/wildfly-10.1.0.Final/modules/system/layers/base/org/postgresql/main</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>                    
            </executions>
        </plugin>            
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.2</version>
            <executions>
                <execution>
                    <id>copy-standalone-config</id>
                        <phase>process-test-classes</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/wildfly-10.1.0.Final/standalone/configuration</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/test/resources</directory>
                                    <includes>
                                        <include>standalone.xml</include>
                                    </includes>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                </execution>
                <execution>
                    <id>copy-module-xml</id>
                    <phase>process-test-classes</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/wildfly-10.1.0.Final/modules/system/layers/base/org/postgresql/main</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/test/resources</directory>
                                <includes>
                                    <include>module.xml</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>            
        ...
    </plugins>
</build>