是否可以在Wildfly中将数据源部署描述符与驱动程序模块一起使用? [英] Is it possible to use a datasource deployment descriptor with a driver module in Wildfly?
问题描述
我无法使用带有数据库驱动程序作为模块安装的 * -ds.xml部署描述符来配置数据源。
仅当我直接将数据库驱动程序部署为jar时,数据源* -ds.xml文件才有效。
我认为,如果您选择将驱动程序安装为模块,则必须直接在standalone.xml中配置数据源。
我想要解决方案驱动程序模块+部署描述符。
I can´t configure my datasource by using a "*-ds.xml" deployment descriptor with the database driver installed as module. The datasource *-ds.xml file is only valid if I deploy the database driver directly as jar. I think that If you choose to install the driver as a module you will have to configure the datasource in the standalone.xml directly. I would like the solution driver module + deployment descriptor.
推荐答案
为使模块对您的应用程序可见,您需要将模块导入到您的应用程序中。对于您的应用程序,您需要在WEB-INF中使用jboss-deployment-structure.xml,如下所示:
For your module to be visible to your application, you need to import the module to your application. You need jboss-deployment-structure.xml in your WEB-INF for your application, something like this:
<?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。
After that, the module and the driver should be visible for your app as well as to your *-ds.xml.
这是在* -ds.xml中表示要使用模块驱动程序的方法:
This is the way to say in *-ds.xml that you want to use a driver from a module:
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
(使用postgresql配置的示例,因为您似乎正在使用它)
(example using postgresql configuration, since you seem to be using that)
编辑:使用以下作为postgresql-ds.xml进行了测试:
Tested this using following as 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可以做到:
However, with Wildfly 10 it gives this:
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中创建它,并引用其中的模块。 此论坛链接似乎证实了这一点。
I tested also on Wildfly 8.1, where the message is same. So it seems deploying a datasource configuration in -ds.xml is not supported and you need to create it in standalone.xml, referencing to module there. This forum link seems to confirm that.
该链接还说明您可以使用.ear / .war描述符定义数据源,无论如何这可能更适合您的用例。我使用.war文件和web.xml创建了一个示例,分别位于此处和此答案表明您可以使用.ears 进行相同操作。可以说它比-ds.xml更好,因为它是标准。
What the link also says that you can define a data source using .ear/.war descriptors, which might be a better fit for your use case anyway. I created an example using a .war file and web.xml, located here, and this answer says you can do the same with .ears. Arguably it's even better than -ds.xml, since it is a standard.
这篇关于是否可以在Wildfly中将数据源部署描述符与驱动程序模块一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!