postgresql Wildfly 10 中的数据源配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43408668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:33:06  来源:igfitidea点击:

Datasource configuration in wildfly 10

postgresqljakarta-eedatasourcewildfly

提问by arjacsoh

I am trying to configure a PostgreSQL datasource in Wildfly 10 Application Server on Mac OS. I am doing what the instructions prescribe. I have created an order:

我正在尝试在 Mac OS 上的 Wildfly 10 应用程序服务器中配置 PostgreSQL 数据源。我正在按照说明进行操作。我创建了一个订单:

/wildfly-10.1.0.Final/modules/system/layers/base/org/postgresql/main. 

In this order I have put the JDBC driver:

我按照这个顺序放置了 JDBC 驱动程序:

postgresql-9.3-1104.jdbc4.jar

and I have created a module.xmlfile:

我创建了一个module.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql“>
  <resources>
    <resource-root path="postgresql-9.3-1104.jdbc4.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

In the standalone.xml file I have created the datasource under datasources:

在 standalone.xml 文件中,我在数据源下创建了数据源:

     <datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true"
                        use-java-context="true">
   <connection-url>jdbc:postgresql://localhost:5432/testdb</connection-url>
         <driver>postgresql</driver>
            <security>
             <user-name>user</user-name>
             <password>password</password>
            </security>
            <validation>
              <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"></valid-connection-checker>
              <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"></exception-sorter>
     </validation>
   </datasource>

and drivers as:

和驱动程序为:

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

However it is impossible the datasource is not installed and when I start the server I get the message (error):

但是不可能没有安装数据源,当我启动服务器时,我收到消息(错误):

ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
            ("subsystem" => "datasources"),
            ("data-source" => "PostgresDS")
        ]) - failure description: {
            "WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.postgresql"],
            "WFLYCTL0180: Services with missing/unavailable dependencies" => [
                "org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]",
                "jboss.driver-demander.java:jboss/datasources/PostgresDS is missing [jboss.jdbc-driver.postgresql]"
            ]
        }
    [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
        ("subsystem" => "datasources"),
        ("data-source" => "PostgresDS")
    ]) - failure description: {
        "WFLYCTL0412: Required services that are not installed:" => [
            "jboss.jdbc-driver.postgresql",
            "jboss.jdbc-driver.postgresql"
        ],
        "WFLYCTL0180: Services with missing/unavailable dependencies" => [
            "org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]",
            "jboss.driver-demander.java:jboss/datasources/PostgresDS is missing [jboss.jdbc-driver.postgresql]",
            "org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]"
        ]
    }

It seems, that wildflymaybe does not find the module. Any ideas what causes this problem? Is anything wrong in my configuration?

看来,wildfly可能没有找到该模块。任何想法是什么导致了这个问题?我的配置有问题吗?

回答by stdunbar

I'd like to recommend a change to your process. While you certainly can do this by hand, if you script this you can do it again with repeatability.

我想建议对您的流程进行更改。虽然您当然可以手动执行此操作,但如果您编写此脚本,则可以重复执行此操作。

This is dependent on the jboss-cli.sh. I have a script that looks like:

这取决于 jboss-cli.sh。我有一个看起来像的脚本:

embed-server --std-out=echo --server-config=standalone.xml

batch

module add --name=org.postgres --resources=/tmp/postgresql-42.0.0.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/data-source=myDataSource/:add(connection-url=jdbc:postgresql://localhost:5432/thedatabasename,driver-name=postgres,jndi-name=java:/jdbc/myDataSource,initial-pool-size=4,max-pool-size=64,min-pool-size=4,password=theDatabasePassword,user-name=theDatabaseUsername)

run-batch

This is run with:

这是运行的:

bin/jboss-cli.sh --file=/path/to/file/wildflyconf.cli

The script starts by using the "embed-server" command so that your Wildfly instance does not need to be running. Then it starts a batch of commands to run as one unit.

该脚本首先使用“embed-server”命令,因此您的 Wildfly 实例不需要运行。然后它启动一批命令作为一个单元运行。

The important part is that we create the module via the command line. You will have to put the PostgreSQL jar somewhere but other than that the script takes care of creating all of the needed files under "modules".

重要的部分是我们通过命令行创建模块。您必须将 PostgreSQL jar 放在某个地方,但除此之外,脚本负责在“模块”下创建所有需要的文件。

Next, we add the JDBC driver and then we create a Datasource based on the driver.

接下来,我们添加 JDBC 驱动程序,然后我们基于该驱动程序创建一个数据源。

The advantage of a script is that you can check this into your source code control system and anyone can run it. It reduces the possibility of a typo and you don't need to manually create and modify files.

脚本的优点是您可以将其检入源代码控制系统,任何人都可以运行它。它减少了拼写错误的可能性,您无需手动创建和修改文件。

Just a thought. Having a repeatable process that your development team can use is always a useful thing.

只是一个想法。拥有一个您的开发团队可以使用的可重复流程总是一件有用的事情。

回答by ehsavoie

You are defining your Driver class as a Datasource class :

您将 Driver 类定义为 Datasource 类:

<datasource-class>org.postgresql.Driver</datasource-class>

please use the correct element:

请使用正确的元素:

<driver-class>org.postgresql.Driver</driver-class>

just like @stdunbar showed you in his CLI command :

就像@stdunbar 在他的 CLI 命令中向您展示的那样:

/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)

回答by AleKennedy

in your file module.xml in the 2nd line change

在您的文件 module.xml 中的第二行更改

<module xmlns="urn:jboss:module:1.3" name="org.postgresql“>

to

<module xmlns="urn:jboss:module:1.3" name="org.postgresql">

the ' "' may be the problem in your module.xml

' "' 可能是你的 module.xml 中的问题

回答by bibekaa

Set the following system properties in standalone.xmland it should work fine:

设置以下系统属性standalone.xml,它应该可以正常工作:

-Dorg.kie.server.persistence.dialect=org.hibernate.dialect.PostgreSQLDialect

-Dorg.kie.server.persistence.ds=java:jboss/datasources/yourDataSource

-Dorg.kie.server.persistence.dialect=org.hibernate.dialect.PostgreSQLDialect

-Dorg.kie.server.persistence.ds=java:jboss/datasources/yourDataSource

<system-properties>
    <property name="org.kie.server.persistence.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
    <property name="org.kie.server.persistence.ds" value="java:jboss/datasources/ExampleDS"/>
</system-properties>