wildfly中的数据源配置10 [英] Datasource configuration in wildfly 10

查看:242
本文介绍了wildfly中的数据源配置10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Mac OS上的Wildfly 10 Application Server中配置PostgreSQL数据源。我正在按照说明书的规定行事。我创建了一个订单:

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:

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

按此顺序我放了JDBC驱动程序:

In this order I have put the JDBC driver:

postgresql-9.3-1104.jdbc4.jar

我创建了一个 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>

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

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

     <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>

和司机为:

<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]"
        ]
    }

看来, wildfly 可能找不到该模块。是什么原因导致了这个问题?我的配置有什么问题吗?

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

推荐答案

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

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.

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

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

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

这是运行:

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

该脚本首先使用embed-server命令启动,以便您的Wildfly实例不会ed正在运行。然后它启动一批命令作为一个单元运行。

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.

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

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".

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

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

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

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.

这篇关于wildfly中的数据源配置10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆