javalite 的持久层 activejdbc 提供了DataSource创建数据库连接的方式,所以理论上来讲可以使用市面上任何的数据库连接池DataSource来实现数据库连接。这里我们选择阿里出品的Druid吧。首先在类路径下编写Druid的配置文件
druid.url = jdbc:mysql://127.0.0.1:3306/jhbims?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
druid.username = test
druid.password = test
druid.driverClassName = com.mysql.jdbc.Driver
druid.initialSize = 5
druid.minIdle = 3
druid.maxActive = 100
drud.maxWait = 1000
druid.testOnBorrow = true
druid.filters = stat,wall
然后在DbConfig类中配置数据源
Properties properties = new Properties();
try {
properties.load(DbConfig.class.getClassLoader().getResourceAsStream("druidConfig.properties"));
} catch (IOException e) {
logger.error("读取druid配置失败");
}
DruidDataSource dataSource = new DruidDataSource();
dataSource.configFromPropety(properties);
environment("development").dataSource(dataSour