这一节,重要,需要认真解析
com.alibaba.druid.pool.DruidDataSource
首先整合Mybatis + Druid,配置文件怎么写?
模板如下:
下面给出我的
具体实现:
package user.defined;import java.util.Properties;import javax.sql.DataSource;public class MyDataSourceFactory implements org.apache.ibatis.datasource.DataSourceFactory { protected Properties properties; @Override public void setProperties(Properties props) { this.properties = props; } @Override public DataSource getDataSource() { try { javax.sql.DataSource dataSource = com.alibaba.druid.pool.DruidDataSourceFactory .createDataSource(properties); return dataSource; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("init data source error", e); } }}