为了使您的模块对您的应用程序可见,您需要将该模块导入到您的应用程序中。您的应用程序的 WEB-INF 中需要 jboss-deployment-struct.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 中创建它,并引用那里的模块。似乎证实了这一点。
该链接还表明您可以使用 .ear/.war 描述符定义数据源,无论如何,这可能更适合您的用例。我使用 .war 文件和 web.xml 创建了一个示例,位于here https://github.com/eis/wildfly-modules, and 这个答案说你可以对 .ears 做同样的事情 https://stackoverflow.com/a/16261491/365237。可以说它甚至比 -ds.xml 更好,因为它是一个标准。