/** * 配置数据源 * * @param ds * @return * @throws SQLException */ @Bean(initMethod = "init", destroyMethod = "close") public DataSource dataSource(DruidSettings ds) { DruidDataSource dataSource = new DruidDataSource(); dataSource.setUrl(ds.getUrl()); dataSource.setUsername(ds.getUsername()); dataSource.setPassword(ds.getPassword()); dataSource.setInitialSize(ds.getInitialSize()); dataSource.setMaxActive(ds.getMaxActive()); dataSource.setMinIdle(ds.getMinIdle()); dataSource.setMaxWait(ds.getMaxWait()); dataSource.setValidationQuery(ds.getValidationQuery()); dataSource.setTimeBetweenEvictionRunsMillis(ds.getTimeBetweenEvictionRunsMillis()); dataSource.setMinEvictableIdleTimeMillis(ds.getMinEvictableIdleTimeMillis()); dataSource.setTestWhileIdle(ds.isTestWhileIdle()); dataSource.setTestOnBorrow(ds.isTestOnBorrow()); dataSource.setTestOnReturn(ds.isTestOnReturn()); dataSource.setPoolPreparedStatements(ds.isPoolPreparedStatements()); dataSource.setMaxOpenPreparedStatements(ds.getMaxOpenPreparedStatements()); try { dataSource.setFilters(ds.getFilters()); } catch (SQLException e) { e.printStackTrace(); LOGGER.error("init druid source error", e); } LOGGER.debug("init druid source"); return dataSource; }
protected void setUp() throws Exception { Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size()); dataSource = new DruidDataSource(); dataSource.setExceptionSorter(new OracleExceptionSorter()); dataSource.setDriver(new OracleMockDriver()); dataSource.setUrl("jdbc:mock:xxx"); dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(100); }