如何将 PostgreSQL 数据源添加到 WildFly 9.0?
How to add PostgreSQL datasource to WildFly 9.0?
我在 mastertheboss.com 上尝试过教程:
- ./jboss-cli.sh
- module add --name=org.postgres --resources=/tmp/postgresql-9.3-1101.jdbc41.jar --dependencies=javax.api,javax.transaction.api
- /subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
- data-source add --jndi-name=java:/PostGreDS --name=PostgrePool --connection-url=jdbc:postgresql://localhost/postgres --driver-name=postgres --user-name=postgres --password=postgres
本教程适用于 WildFly 8.2,但不适用于 WildFly 9.0。第三步失败并显示错误消息:
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
如何将 Postgres 数据源添加到 WildFly 9.0?
我遇到了与 WildFly 9 相同的错误和行为。我是 WF 的新手,但经过一番研究,我发现问题出在模块命名上。
如果我没听错,模块中的实际包名将用于解析 module.xml 的路径。
我已将步骤更改为以下步骤并且有效:
module add --name=org.postgresql --slot=main --resources=/usr/local/lib/postgresql-9.4-1201.jdbc4.jar --dependencies=javax.api,javax.transaction.api
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
我在 docker 中运行 wildfly 10:
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
module.xml 在哪里
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
并且独立包含驱动程序:
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
那么数据源可以是:
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
请注意,我的 ndis-db 是一个 postgres docker。在你的情况下可以是 localhost.
我是如何得到你提到的错误的:
1.文件名拼写错误
2. /modules/org ...等包含错字
3. module.xml 拼错为modules.xml
4. ...
它非常简单,但如果您是 JBOSS EAP/WilFly 的新手,可能需要更多时间
使用以下步骤创建数据源:
转到存在 jboss-cli(Power 脚本)文件的服务器的 bin 文件夹:right click on jboss-cli(power script file)--> Run with power shell(将打开一个控制台)。
将 PostgreSQL JDBC 驱动程序添加为核心模块。
module add --name=com.postgresql
--resources=/path/to/postgresql-9.3-1102.jdbc4.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=com.postgresql,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)
data-source add --name=PostgresDS --jndi-name=java:jboss/PostgresDS
--driver-name=postgresql --connection-url=jdbc:postgresql://localhost:5432/postgresdb --user-name=admin --password=admin --validate-on-match=true --background-validation=false --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker
--exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter
注意路径 path/to 这是您下载的 Postgresql-jdbc.jar 所在的路径。
将您的 Postgres JDBC 驱动程序放入部署文件夹(只需部署)。
现在使用 CLI 控制台并输入以下命令:
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
检查你的驱动是否是jdbc4.
我不知道为什么,但是通过 Web 控制台添加数据源不起作用。通过 CLI 工作。
扩展 JDBC 驱动程序的正确解决方案是将驱动程序作为模块添加到服务器。
在 WildFly 9 中,您可以使用 cli 控制台进行操作。您不能通过将 JDBC jar 文件(带有 xml)复制到 WildFly 8 中的"module"文件夹来执行此操作。
执行命令:
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
要列出已安装的驱动程序,请输入:
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
使用驱动程序创建数据源将很容易。
请使用 9.0 最终版。在 CR 中有错误。
问候,
帕维尔 M
请注意:我已经针对 WildFly 10 测试了上述教程中的 CLI 命令,它在创建 JDBC 驱动程序和数据源时可以正常工作。
除此之外,我可以看到报告的错误日志包含模块名称的拼写错误 ("org.portgres"):
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
免责声明:我是mastertheboss.com的所有者
你没有提到你的 java/jdbc 版本。我刚刚遇到了同样的问题,这是由于驱动程序与 Java 1.8 不匹配造成的。通过 wildfly 9 升级,您是否还升级了 Java?
".jdbc41." 驱动程序版本是为 Java 1.7 构建的。 Postgres 有一个矩阵显示兼容的 Java/JDBC 和 Postgres 驱动程序版本的组合。也许您需要:postgresql-9.4.1209.jar(适用于 1.8/jdbc42)
然后在 CLI 中(假设域模式和 profile=full)
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
/subsystem=datasources:installed-drivers-list
{
"outcome" =>"failed",
"failure-description" =>"WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit