是否可以在Wildfly中将数据源部署描述符与驱动程序模块一起使用?

Lau*_*ulo 4 deployment datasource wildfly

我无法通过将“ * -ds.xml”部署描述符与数据库驱动程序一起安装为模块来配置数据源。仅当我直接将数据库驱动程序部署为jar时,数据源* -ds.xml文件才有效。我认为,如果选择将驱动程序安装为模块,则必须直接在standalone.xml中配置数据源。我想要解决方案驱动程序模块+部署描述符。

eis*_*eis 5

为了使模块对您的应用程序可见,您需要将模块导入到您的应用程序。您的应用程序需要WEB-INF中的jboss-deployment-structure.xml,如下所示:

<?xml version="1.0"?>
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.postgresql" services="export">
                <imports>
                    <include path="META-INF**"/>
                    <include path="org**"/> 
                    <!-- assuming package of the driver is org.something -->
                </imports>
            </module>
        </dependencies>
    </deployment>
</jboss-deployment-structure>
Run Code Online (Sandbox Code Playgroud)

之后,模块和驱动程序对于您的应用程序以及* -ds.xml都应该可见。

这是在* -ds.xml中表示要使用模块驱动程序的方法:

<driver name="postgresql" module="org.postgresql">
  <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
Run Code Online (Sandbox Code Playgroud)

(使用postgresql配置的示例,因为您似乎正在使用该配置)

编辑:使用以下作为postgresql-ds.xml对此进行了测试:

<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_1.xsd">
    <datasource jndi-name="java:jboss/datasources/PostgeSQLDB " pool-name="PostgreSQLPool">
        <connection-url>jdbc:postgresql://localhost:5432/example
        </connection-url>
        <driver>postgres</driver>
        <pool>
            <max-pool-size>30</max-pool-size>
        </pool>
        <security>
            <user-name>postgresql</user-name>
            <password>postgresql</password>
        </security>
    </datasource>
    <drivers>
        <driver name="postgresql" module="org.postgresql">
            <xa-datasource-class>org.postgresql.xa.PGXADataSource
            </xa-datasource-class>
        </driver>
    </drivers>
</datasources>
Run Code Online (Sandbox Code Playgroud)

但是,使用Wildfly 10可以达到以下目的:

20:17:22,895 WARN  [org.jboss.as.connector] (MSC service thread 1-2) WFLYJCA0091: -ds.xml file deployments are deprecated. Support
 may be removed in a future version.
20:17:23,058 WARN  [org.jboss.as.connector.deployer.dsdeployer] (MSC service thread 1-1) WFLYJCA0012: <drivers/> in standalone -ds
.xml deployments aren't supported: Ignoring my-spring-app.war
Run Code Online (Sandbox Code Playgroud)

我还在消息相同的Wildfly 8.1上进行了测试。因此,似乎不支持在-ds.xml中部署数据源配置,因此您需要在standalone.xml中创建它,并参考其中的模块。这个论坛链接似乎证实了这一点。

链接还说明您可以使用.ear / .war描述符定义数据源,无论如何这可能更适合您的用例。我使用位于此处的.war文件和web.xml创建了一个示例,此答案表明您可以使用.ears进行相同操作。可以说它比-ds.xml更好,因为它是一个标准。