配置jboss数据源
1 配置mysql数据源
在D:\tools\service\jboss-as-7.1.1.Final\modules\com目录下新建
mysqldatabase\mysql\main
将数据库链接驱动放到该文件夹下
新建module.xml,示例代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1"name="com.mysqldatabase.mysql">
<resources>
<resource-rootpath="mysql-connector-java-5.1.12-bin.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api"optional="true"/>
</dependencies>
</module>
修改D:\tools\service\jboss-as-7.1.1.Final\standalone\configuration目录下的standlone.xml文件,示例代码如下:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS"pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jndi-name="java:/MySqlDS"pool-name="MySqlDS" enabled="true"use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/shop</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>password</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql"module="com.mysqldatabase.mysql">
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
2 配置oracle数据源
在D:\tools\service\jboss-as-7.1.1.Final\modules\com目录下新建
oracledatabase\oracle\main
将数据库链接驱动放到该文件夹下
新建module.xml,示例代码如下:
<?xml version="1.0"encoding="UTF-8"?>
<modulexmlns="urn:jboss:module:1.1"name="com.oracledatabase.oracle">
<resources>
<resource-rootpath="ojdbc14.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<modulename="javax.api"/>
<module name="javax.transaction.api"/>
<modulename="javax.servlet.api" optional="true"/>
</dependencies>
</module>
修改D:\tools\service\jboss-as-7.1.1.Final\standalone\configuration目录下的
Standalone.xml文件,示例代码如下:
<subsystemxmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasourcejndi-name="java:jboss/datasources/ExampleDS"pool-name="ExampleDS" enabled="true"use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasourcejndi-name="java:/MySqlDS" pool-name="MySqlDS"enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/shop</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>yue4512138</password>
</security>
</datasource>
<datasourcejndi-name="java:/OracleDS" pool-name="OracleDS"enabled="true" use-java-context="true">
<connection-url>jdbc:oracle:thin:@localhost:1521:RETACN</connection-url>
<driver>oracle</driver>
<security>
<user-name>bb</user-name>
<password>yue4512138</password>
</security>
</datasource>
<drivers>
<driver name="h2"module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql"module="com.mysqldatabase.mysql">
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
<driver name="oracle"module="com.oracledatabase.oracle">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
配置完成后重启服务器,显示结果如下:
12:02:14,327 INFO[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4)JBAS010400: Bound data source [java:/OracleDS]
12:02:14,327 INFO[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8)JBAS010400: Bound data source [java:/MySqlDS]
12:02:14,327 INFO[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3)JBAS010400: Bound data source [java:jboss/datasources/Exam
pleDS]
也可以通过浏览器的控件台查看结果如下:http://localhost:9990/
说明数据源配置成功