首页 文章

无法为驱动程序org.postgresq加载模块

提问于
浏览
2

我想通过声明数据源在 Jboss Wildfly Swarm 中使用postgresql . 应用程序启动错误消息是:

无法为驱动程序org.postgresq加载模块

主类内容:

public static void main(String[] args) throws Exception {
            Container container = new Container();



    container.fraction(new DatasourcesFraction()
                    .jdbcDriver("postgresql", (d) -> {

      d.driverDatasourceClassName("org.postgresql.Driver");

      d.xaDatasourceClass("org.postgresql.xa.PGXADataSource");
      d.driverModuleName("org.postgresql");
                    })
    .dataSource("ExampleDS", (ds) -> {
      ds.driverName("postgresql");

      ds.connectionUrl("jdbc:postgresql://localhost:5432/test_db");
      ds.userName("sa");
      ds.password("sa");
                    })
    );
            container.start();

            JAXRSDeployment appDeployment = new JAXRSDeployment( container );
            appDeployment.addResource(MyResource.class);

            container.deploy(appDeployment);
        }

谢谢你的帮助

1 回答

  • 1

    以下wildfly-swarm示例可能很有用 . 它描述了如何在Wildfly Swarm容器中部署驱动程序和数据源:(有IT测试覆盖它)

    https://github.com/wildfly-swarm/wildfly-swarm-examples/tree/master/datasource/datasource-deployment

    编辑:数据源部署示例文档不是最新的,有效示例here

    以下是运行此示例main方法时的日志 . 数据源部署似乎工作正常:

    20:00:19,081 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
    20:00:19,491 INFO  [org.jboss.as] (MSC service thread 1-7) WFLYSRV0049: WildFly Core 2.0.0.CR8 "Kenny" starting
    2015-12-05 20:00:20,683 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 16) WFLYNAM0001: Activating Naming Subsystem
    2015-12-05 20:00:20,673 WARN  [org.jboss.as.txn] (ServerService Thread Pool -- 20) WFLYTX0013: Node identifier property is set to the default value. Please make sure it is unique.
    2015-12-05 20:00:20,701 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 17) WFLYSEC0002: Activating Security Subsystem
    2015-12-05 20:00:20,726 INFO  [org.wildfly.extension.io] (ServerService Thread Pool -- 14) WFLYIO001: Worker 'default' has auto-configured to 8 core threads with 64 task threads based on your 4 available processors
    2015-12-05 20:00:20,740 INFO  [org.jboss.as.naming] (MSC service thread 1-1) WFLYNAM0003: Starting Naming Service
    2015-12-05 20:00:20,754 INFO  [org.jboss.as.security] (MSC service thread 1-4) WFLYSEC0001: Current PicketBox version=4.9.3.Final
    2015-12-05 20:00:20,781 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0003: Undertow 1.3.3.Final starting
    2015-12-05 20:00:20,783 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 13) WFLYUT0003: Undertow 1.3.3.Final starting
    2015-12-05 20:00:20,812 INFO  [org.jboss.as.connector] (MSC service thread 1-2) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.3.1.Final)
    2015-12-05 20:00:20,948 INFO  [org.xnio] (MSC service thread 1-1) XNIO version 3.3.2.Final
    2015-12-05 20:00:20,979 INFO  [org.xnio.nio] (MSC service thread 1-1) XNIO NIO Implementation Version 3.3.2.Final
    2015-12-05 20:00:21,071 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0012: Started server default-server.
    2015-12-05 20:00:21,189 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0006: Undertow HTTP listener default listening on [0:0:0:0:0:0:0:0]:8080
    2015-12-05 20:00:24,250 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Core 2.0.0.CR8 "Kenny" started in 5336ms - Started 106 of 113 services (18 services are lazy, passive or on-demand)
    2015-12-05 20:00:24,274 ERROR [stderr] (main) found version: 1.4.187
    2015-12-05 20:00:24,802 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0027: Starting deployment of "h2" (runtime-name: "h2")
    2015-12-05 20:00:25,160 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)
    2015-12-05 20:00:25,181 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0018: Started Driver service with driver-name = h2
    2015-12-05 20:00:25,252 INFO  [org.jboss.as.server] (main) WFLYSRV0010: Deployed "h2" (runtime-name : "h2")
    2015-12-05 20:00:25,272 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0027: Starting deployment of "864c873e-444b-4d35-89f4-c7b333afc3bc.jar" (runtime-name: "864c873e-444b-4d35-89f4-c7b333afc3bc.jar")
    2015-12-05 20:00:25,333 WARN  [org.jboss.as.connector] (MSC service thread 1-7) WFLYJCA0091: -ds.xml file deployments are deprecated. Support may be removed in a future version.
    2015-12-05 20:00:25,441 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
    2015-12-05 20:00:25,507 INFO  [org.jboss.as.server] (main) WFLYSRV0010: Deployed "864c873e-444b-4d35-89f4-c7b333afc3bc.jar" (runtime-name : "864c873e-444b-4d35-89f4-c7b333afc3bc.jar")
    2015-12-05 20:00:25,624 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0027: Starting deployment of "3736861a-1203-41d5-a5c3-963193b1975b.war" (runtime-name: "3736861a-1203-41d5-a5c3-963193b1975b.war")
    2015-12-05 20:00:25,812 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0018: Host default-host starting
    2015-12-05 20:00:26,143 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 10) RESTEASY002225: Deploying javax.ws.rs.core.Application: class org.wildfly.swarm.generated.WildFlySwarmDefaultJAXRSApplication
    2015-12-05 20:00:26,186 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 10) WFLYUT0021: Registered web context: /
    2015-12-05 20:00:26,273 INFO  [org.jboss.as.server] (main) WFLYSRV0010: Deployed "3736861a-1203-41d5-a5c3-963193b1975b.war" (runtime-name : "3736861a-1203-41d5-a5c3-963193b1975b.war")
    

    您是否还在类路径中添加了驱动程序库,如果您正在使用maven,则通过在运行时依赖项中声明它?

相关问题