是否可以在Wildfly中使用带有驱动程序模块的数据源部署描述符?

时间:2016-02-23 16:14:55

标签: deployment datasource wildfly

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

2 个答案:

答案 0 :(得分:4)

要使您的模块对您的应用程序可见,您需要将模块导入您的应用程序。您的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>

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

这是在* -ds.xml中说你想要从模块中使用驱动程序的方法:

<driver name="postgresql" module="org.postgresql">
  <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>

(使用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>

然而,对于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

我也在Wildfly 8.1上测试过,消息是相同的。因此,似乎不支持在-ds.xml中部署数据源配置,您需要在standalone.xml中创建它,并在那里引用模块。 This forum link似乎证实了这一点。

链接还表示您可以使用.ear / .war描述符定义数据源,这可能更适合您的用例。我使用位于herethis answer says you can do the same with .ears的.war文件和web.xml创建了一个示例。可以说它比-ds.xml更好,因为它是一个标准。

答案 1 :(得分:1)

我感谢eis,将jboss-deployment-descriptor放在ear存档的META-INF文件夹中: - )

无论如何,我现在必须直接将驱动程序放在standalone.xml文件中:

     <driver name="postgresql-9_2-1002_jdbc4_jar" module="org.postgresql">
            <driver-class>org.postgresql.Driver</driver-class>
        </driver>

使用jar部署,我可以直接将它放在* -ds.xml文件中。我认为这是可能的。我不放弃。