[英]Using MySQL replication (Master/Slave) with MyBatis
I am just wondering how I can use a Master/Slave MySQL replication database with MyBatis.我只是想知道如何将主/从 MySQL 复制数据库与 MyBatis 一起使用。 JDBC offers a com.mysql.jdbc.ReplicationDriver
(see here ), but I couldn't find out where I can use similar things including all the nice properties I can configure ( roundRobinLoadBalance , autoReconnect ,...) in MyBatis. JDBC offers a com.mysql.jdbc.ReplicationDriver
(see here ), but I couldn't find out where I can use similar things including all the nice properties I can configure ( roundRobinLoadBalance , autoReconnect ,...) in MyBatis.
Currently I have configured my none-replicated database in MyBatis like this:目前我已经在 MyBatis 中配置了我的非复制数据库,如下所示:
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://localhost:3306/database" />
<property name="username" value="root" />
<property name="password" value="" />
</dataSource>
</environment>
<environment id="production">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://xxx:3306/database" />
<property name="username" value="production" />
<property name="password" value="" />
</dataSource>
</environment>
</environments>
Has anyone aa hint for me?有人给我提示吗?
Thanks for your help.谢谢你的帮助。
Daniel丹尼尔
ANOTHER POSSIBLE ANSWER另一个可能的答案
If you notice, the properties you're setting in the xml for the driver are also common properties set and passed to jdbc.如果您注意到,您在 xml 中为驱动程序设置的属性也是设置并传递给 jdbc 的常用属性。 So, I wouldn't be surprised if MyBatis was just taking them and passing them right into the driver.因此,如果 MyBatis 只是将它们接收并直接传递给驱动程序,我不会感到惊讶。 So maybe try this:所以也许试试这个:
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<!-- Just use ReplicationDriver -->
<property name="driver" value="com.mysql.jdbc.ReplicationDriver" />
<property name="url"
value="jdbc:mysql://localhost:3306/database" />
<property name="autoReconnect" value="true" />
<property name="roundRobinLoadBalance" value="true" />
<property name="username" value="root" />
<property name="password" value="" />
</dataSource>
</environment>
<environment id="production">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<!-- Just use ReplicationDriver -->
<property name="driver" value="com.mysql.jdbc.ReplicationDriver" />
<property name="url"
value="jdbc:mysql://xxx:3306/database" />
<property name="autoReconnect" value="true" />
<property name="roundRobinLoadBalance" value="true" />
<property name="username" value="production" />
<property name="password" value="" />
</dataSource>
</environment>
</environments>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.