jboss-eap-6.3集成OracleDS和MySqlDS配置

时间:2022-04-17 21:38:35

jboss-eap-6.3集成OracleDS和MySqlDS


Oracl:

  1. 在D:\tools\jboss\jboss-eap-6.3\modules\system\layers\base\com目录下新建oracle\main文件夹:

  2. 在此文件夹下添加ojdbc14-10.2.0.4.0.jar和module.xml,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.oracle">
    <properties>
        <property name="jboss.api" value="public"/>
    </properties>
    <resources>
        <resource-root path="ojdbc14-10.2.0.4.0.jar"/>
        <!-- Insert resources here -->
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>
</module>

3. 修改D:\tools\jboss\jboss-eap-6.3\standalone\configuration\standalone.xml文件,添加如下代码:

<datasource jta="true" jndi-name="java:jboss/datasources/OracleDS" pool-name="OracleDS" enabled="true" use-java-context="true">
            <connection-url>jdbc:oracle:thin:@127.0.0.1:1521:ORCL</connection-url>
             <driver>oracle</driver>
             <pool>
             <prefill>false</prefill>
                    <use-strict-min>false</use-strict-min>
                    <flush-strategy>FailingConnectionOnly</flush-strategy>
             </pool>
             <security>
                        <user-name>scott</user-name>
                        <password>tigger</password>
           </security>
</datasource>
<driver name="oracle" module="com.oracle">
           <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
            <xa-datasource-class>com.mysql.jdbc.Driver</xa-datasource-class>
</driver>


MySql:

  1. 在D:\tools\jboss\jboss-eap-6.3\modules\system\layers\base\com目录下新建mysql\main文件夹:

  2. 在此文件夹下添加mysql-connector-java-5.1.29.jar(注意:使用5.1.29以上的版本会报错,详见本文扩展部分)和module.xml,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
    <properties>
        <property name="jboss.api" value="public"/>
    </properties>
    <resources>
        <resource-root path="mysql-connector-java-5.1.29.jar"/>
        <!-- Insert resources here -->
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>
</module>

3.修改D:\tools\jboss\jboss-eap-6.3\standalone\configuration\standalone.xml文件,添加如下代码:

 <datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true">
                    <connection-url>jdbc:mysql://127.0.0.1:3306/demo</connection-url>
                    <driver>mysql</driver>
                    <security>
                        <user-name>root</user-name>
                        <password>root</password>
                    </security>
                </datasource>

                <driver name="mysql" module="com.mysql">
                        <driver-class>com.mysql.jdbc.Driver</driver-class>
                        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                 </driver>

扩展:

集成mysql开始时使用了:mysql-connector-java-5.1.34.jar,启动时报错:

12:23:10,872 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 25) JBAS010404: 部署不兼容 JDBC 的驱动 class com.mysql.fabric.jdbc.FabricMySQLDriver (版本 5.1)

12:23:10,880 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 25) JBAS014612: 操作("add") 失败 -- 地址:([

    ("subsystem" => "datasources"),

    ("jdbc-driver" => "mysql")

]): org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.mysql is already registered

at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:158) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

at org.jboss.msc.service.ServiceControllerImpl.startInstallation(ServiceControllerImpl.java:236) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

at org.jboss.msc.service.ServiceContainerImpl.install(ServiceContainerImpl.java:742) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:243) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2433) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

at org.jboss.msc.service.ServiceBuilderImpl.install(ServiceBuilderImpl.java:345) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

at org.jboss.as.controller.OperationContextImpl$ContextServiceBuilder.install(OperationContextImpl.java:1672) [jboss-as-controller-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]

at org.jboss.as.connector.subsystems.datasources.JdbcDriverAdd.startDriverServices(JdbcDriverAdd.java:160)

at org.jboss.as.connector.subsystems.datasources.JdbcDriverAdd.performRuntime(JdbcDriverAdd.java:118)

at org.jboss.as.controller.AbstractAddStepHandler$1.execute(AbstractAddStepHandler.java:75) [jboss-as-controller-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]

at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:611) [jboss-as-controller-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]

at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:489) [jboss-as-controller-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]

at org.jboss.as.controller.AbstractOperationContext.completeStepInternal(AbstractOperationContext.java:290) [jboss-as-controller-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]

at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:285) [jboss-as-controller-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]

at org.jboss.as.controller.ParallelBootOperationStepHandler$ParallelBootTask.run(ParallelBootOperationStepHandler.java:354) [jboss-as-controller-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]

at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]

at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final-redhat-1.jar:2.1.1.Final-redhat-1]


分析错误原因,mysql驱动加载重复了,部署的JDBC 的驱动 class com.mysql.fabric.jdbc.FabricMySQLDriver正常,但紧接着又部署了一个mysql的数据源,连接mysql时驱动一般是com.mysql.jdbc.Driver,为什么现在是com.mysql.fabric.jdbc.FabricMySQLDriver呢.

换成mysql-connector-java-5.1.29.jar后就不报错了.比较了jar后得知从mysql-connector-java-5.1.30.jar开始jar中多出了fabric的驱动,在META-INF\services\java.sql.Driver文件中包含两行

com.mysql.jdbc.Driver

com.mysql.fabric.jdbc.FabricMySQLDriver


而5.1.29中只包含一行

com.mysql.jdbc.Driver.

那么,fabric究竟是什么呢,见下面的文章http://www.mysql.com/products/enterprise/fabric.html