如何将Jboss-as-7.1.1与Postgresql连接 [英] How to connect Jboss-as-7.1.1 with Postgresql

查看:127
本文介绍了如何将Jboss-as-7.1.1与Postgresql连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何将 jboss-as-7.1.1 连接到PostgreSQL吗?

Does anybody know how to connect jboss-as-7.1.1 to PostgreSQL?

推荐答案

(请注意,这是为JBoss AS 7.1.1编写的;如果是较新的版本,请记住这一点,因为情况可能已经发生了变化。)

(Note that this was written for JBoss AS 7.1.1; keep that in mind if on a newer version, as things might have changed.)

下载PgJDBC 。我假设您使用的是 postgresql-9.1-902.jdbc4.jar ,即撰写本文时的当前版本。

现在,将JDBC驱动程序放在 deployments中,将其部署到JBoss AS 7。

Download PgJDBC. I'm assuming you're using postgresql-9.1-902.jdbc4.jar, the current version at time of writing. Adjust any filenames to match if you need a different version.

code>文件夹或在 jboss-cli 中使用 deploy 命令。

Now deploy the JDBC driver to JBoss AS 7 by putting it in the deployments folder or using the deploy command in jboss-cli. This will work for most, but not all, purposes.

或者,您定义一个PostgreSQL JDBC驱动程序模块:

Alternately, you an define a PostgreSQL JDBC driver module:


  1. 创建路径 $ JBOSS_HOME / modules / org / postgresql / main modules / org 部分应该已经存在,为其余目录创建目录。

  2. $中JBOSS_HOME / modules / org / postgresql / main / module.xml 具有以下内容,更改 resource-root 项以供PgJDBC驱动程序引用

  1. Create the path $JBOSS_HOME/modules/org/postgresql/main. The modules/org part should already exist, make directories for the rest.
  2. In $JBOSS_HOME/modules/org/postgresql/main/module.xml with the following content, changing the resource-root entry for the PgJDBC driver to refer to the driver you wish to use.

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
     <resources>
         <resource-root path="postgresql-9.1-902.jdbc4.jar"/>
     </resources>
     <dependencies>
         <module name="javax.api"/>
         <module name="javax.transaction.api"/>
         <module name="javax.servlet.api" optional="true"/>
     </dependencies>
 </module>


  • module.xml 进入同一目录放置 postgresql-9.1-902.jdbc4.jar

  • 启动JBoss AS

  • 打开 jboss-cli 通过运行 $ JBOSS_HOME / bin / jboss-cli --connect

  • 运行命令:

  • Into the same directory as module.xml place postgresql-9.1-902.jdbc4.jar
  • Start JBoss AS
  • Open jboss-cli by running $JBOSS_HOME/bin/jboss-cli --connect
  • Run the command:

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


  • 现在使用 postgresql-driver 作为驱动程序名称来创建任何所需的数据源。

  • Now create any required data sources, etc, using postgresql-driver as the driver name.
  • 您可以通过Web ui使用 jboss-cli data-source create创建数据源。 命令(请参见 data-source --help data-source add --help ),或通过部署 -ds.xml 文件,如下所示:

    You can create a datasource via the web ui, with jboss-cli with the data-source create command (see data-source --help, data-source add --help), or by deploying a -ds.xml file like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <datasources>
      <datasource jndi-name="java:/datasources/some-ds" enabled="true" use-java-context="true"  
            pool-name="some-ds-pool">
        <connection-url>jdbc:postgresql:dbname</connection-url>
        <driver>postgresql-driver</driver>
        <security>
          <user-name>username</user-name>
          <password>password</password>
        </security>
      </datasource>
    </datasources>
    

    这篇关于如何将Jboss-as-7.1.1与Postgresql连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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