数据库
首页 > 数据库> > 如何为JBoss 7数据源配置MySQL ReplicationDriver?

如何为JBoss 7数据源配置MySQL ReplicationDriver?

作者:互联网

我们正在使用MySql 5.5.37和JBoss 7.1.3,以及mysql-connector-java-5.1.22-bin.jar.如何配置JBoss的standalone.xml数据源以连接到MySQL的主从配置?我尝试了以下

            <datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true">
                <connection-url>jdbc:mysql:replication//master.amazonaws.com:3306,slave.amazonaws.com:3306/dbsid?failOverReadOnly=true;roundRobinLoadBalance=true</connection-url>
                <driver>mysql</driver>
                <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
                <pool>
                    <min-pool-size>10</min-pool-size>
                    <max-pool-size>100</max-pool-size>
                    <prefill>true</prefill>
                </pool>
                <security>
                    <user-name>sb</user-name>
                    <password>sb</password>
                </security>
                <statement>
                    <prepared-statement-cache-size>32</prepared-statement-cache-size>
                    <share-prepared-statements>true</share-prepared-statements>
                </statement>
            </datasource>
            <drivers>
                <driver name="mysql" module="com.mysql">
                    <xa-datasource-class>com.mysql.jdbc.ReplicationDriver</xa-datasource-class>
                </driver>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
            </drivers>

但是当我重新启动服务器时,出现了异常……

Caused by: javax.resource.ResourceException: Wrong driver class [class com.mysql.jdbc.Driver] for this connection URL [jdbc:mysql:replication//master.amazonaws.com:3306,slave.amazonaws.com:3306/dbsid?failOverReadOnly=true;roundRobinLoadBalance=true]
        at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:256)
        ... 47 more

我打开了JAR,并确认其中存在ReplicationDriver类.不知道我还应该尝试什么.

解决方法:

对我来说,这有效:

<driver name="com.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>

标签:database-replication,jboss,jdbc,jboss7-x,mysql
来源: https://codeday.me/bug/20191121/2051321.html