日期:2014-05-16  浏览次数:20328 次

mysql 集群 jdbc配置

项目中使用mysql 主从复制,但是用程序实现的读写分离,代码片段如下:

1 public DataSource getDataSource(MethodType methodType) {
2 if (methodType == MethodType.WRITE) {
3 return getDataSource(MasterDataSources);
4 } else {
5 return getDataSource(SlaveDataSources);
6 }
7 }


获取数据源,首先你要确定MethodType 类型,一个是读,一个是写

1 public enum MethodType {
2