cicada.mybatis.config.AliDataSource Maven / Gradle / Ivy
The newest version!
package cicada.mybatis.config;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import com.alibaba.druid.pool.DruidDataSource;
public class AliDataSource
{
/*@Autowired
private Environment env;*/
//@Override
public DataSource dataSource(Environment env)
{
DruidDataSource ds = new DruidDataSource();
ds.setDriverClassName(env.getProperty("jdbc.driverClassName"));
ds.setUrl(env.getProperty("jdbc.url"));
ds.setUsername(env.getProperty("jdbc.username"));
ds.setPassword(env.getProperty("jdbc.password"));
ds.setMaxActive(Integer.parseInt(env.getProperty("jdbc.maxActive")));
ds.setInitialSize(Integer.parseInt(env.getProperty("jdbc.initialSize")));
ds.setMaxWait(Integer.parseInt(env.getProperty("jdbc.maxWait")));
ds.setMinIdle(Integer.parseInt(env.getProperty("jdbc.minIdle")));
ds.setTimeBetweenEvictionRunsMillis(Integer.parseInt(env.getProperty("jdbc.timeBetweenEvictionRunsMillis")));
ds.setMinEvictableIdleTimeMillis(Integer.parseInt(env.getProperty("jdbc.minEvictableIdleTimeMillis")));
ds.setValidationQuery(env.getProperty("jdbc.validationQuery"));
ds.setTestWhileIdle(Boolean.parseBoolean(env.getProperty("jdbc.testWhileIdle")));
ds.setTestOnBorrow(Boolean.parseBoolean(env.getProperty("jdbc.testOnBorrow")));
ds.setTestOnReturn(Boolean.parseBoolean(env.getProperty("jdbc.testOnReturn")));
ds.setPoolPreparedStatements(Boolean.parseBoolean(env.getProperty("jdbc.poolPreparedStatements")));
ds.setMaxPoolPreparedStatementPerConnectionSize(Integer.parseInt(env.getProperty("jdbc.maxPoolPreparedStatementPerConnectionSize")));
try
{
ds.setFilters(env.getProperty("jdbc.filters"));
}
catch (SQLException e)
{
e.printStackTrace();
}
return ds;
}
}