wildfly配置PostgreSQL数据源

wildfly配置PostgreSQL数据源

 

很久以前写过在JBoss AS7上如何配置PostgreSQL数据源,此方法在wildfly上依然有效。不过,通过wildfly的命令行工具可以有更简单的配置方法,步骤如下:

我把postgresql jdbc driver放到了$HOME/devel/lib目录下,因此:

 

cd $HOME/devel/lib
wget http://jdbc.postgresql.org/download/postgresql-9.4.1212.jar
ln -s postgresql-9.4.1212.jar postgresql.jar

 

cd $JBOSS_HOME/bin
./standalone.sh

执行以下命令(注意–name前面是两个短横杠):

 

cd $JBOSS_HOME/bin
$ ./jboss-cli.sh
[standalone@localhost:9990 /] module add –name=org.postgresql –slot=main –resources=/home/subaochen/devel/lib/postgresql.jar –dependencies=javax.api,javax.transaction.api
[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=postgres:add(driver-name=”postgres”,driver-module-name=”org.postgresql”,driver-class-name=org.postgresql.Driver)

继续在jboss-cli命令行下执行(替换为你的数据源名称、用户名和密码即可):

 

[standalone@localhost:9990 /] data-source add –name=labDS –jndi-name=java:jboss/labDS –driver-name=postgres –connection-url=jdbc:postgresql://localhost:5432/lab –user-name=postgres –password=111111 –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
列出当前wildfly的数据源:

 

[standalone@localhost:9990 /] /subsystem=datasources:installed-drivers-list
{
“outcome” => “success”,
“result” => [
{
“driver-name” => “postgres”,
“deployment-name” => undefined,
“driver-module-name” => “org.postgresql”,
“module-slot” => “main”,
“driver-datasource-class-name” => “”,
“driver-xa-datasource-class-name” => “”,
“driver-class-name” => “org.postgresql.Driver”,
“driver-major-version” => 9,
“driver-minor-version” => 4,
“jdbc-compliant” => false
},
{
“driver-name” => “h2”,
“deployment-name” => undefined,
“driver-module-name” => “com.h2database.h2”,
“module-slot” => “main”,
“driver-datasource-class-name” => “”,
“driver-xa-datasource-class-name” => “org.h2.jdbcx.JdbcDataSource”,
“driver-class-name” => “org.h2.Driver”,
“driver-major-version” => 1,
“driver-minor-version” => 3,
“jdbc-compliant” => true
}
]
}

参考资料

 

posted @ 2018-02-08 15:55  h2z  阅读(460)  评论(0编辑  收藏  举报