@Bean public DataSource getDefaultDataSource() { DataSource dataSource = new DataSource(); dataSource.setUrl(env.getProperty("jdbc.url")); dataSource.setUsername(env.getProperty("jdbc.user")); dataSource.setPassword(env.getProperty("jdbc.password")); dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName")); dataSource.setInitialSize(Integer.parseInt(env.getProperty("jdbc.initialSize"))); dataSource.setMaxActive(Integer.parseInt(env.getProperty("jdbc.maxActive"))); dataSource.setValidationQuery(env.getProperty("jdbc.validationQuery")); dataSource.setMaxIdle(Integer.parseInt(env.getProperty("jdbc.maxIdle"))); dataSource.setMinIdle(Integer.parseInt(env.getProperty("jdbc.minIdle"))); dataSource.setMaxWait(Integer.parseInt(env.getProperty("jdbc.maxWait"))); dataSource.setTestOnBorrow(Boolean.parseBoolean(env.getProperty("jdbc.testOnBorrow"))); dataSource.setTestOnReturn(Boolean.parseBoolean(env.getProperty("jdbc.testOnReturn"))); dataSource.setTestWhileIdle(Boolean.parseBoolean(env.getProperty("jdbc.testWhileIdle"))); dataSource.setTimeBetweenEvictionRunsMillis( Integer.parseInt(env.getProperty("jdbc.timeBetweenEvictionRunsMillis"))); dataSource.setNumTestsPerEvictionRun( Integer.parseInt(env.getProperty("jdbc.numTestsPerEvictionRun"))); dataSource.setMinEvictableIdleTimeMillis( Integer.parseInt(env.getProperty("jdbc.minEvictableIdleTimeMillis"))); dataSource.setRemoveAbandonedTimeout( Integer.parseInt(env.getProperty("jdbc.removeAbandonedTimeout"))); dataSource.setRemoveAbandoned(Boolean.parseBoolean(env.getProperty("jdbc.removeAbandoned"))); dataSource.setLogAbandoned(Boolean.parseBoolean(env.getProperty("jdbc.logAbandoned"))); return dataSource; }
public DataSource dataSource() { org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource(); DatabaseConfiguration conf = DatabaseConfiguration.getInstance(); dataSource.setDriverClassName(conf.getDriverClassName()); dataSource.setUsername(conf.getUsername()); dataSource.setPassword(conf.getPassword()); dataSource.setUrl(conf.getUrl()); dataSource.setMaxActive(conf.getMaxActive()); dataSource.setMaxIdle(conf.getMaxIdle()); dataSource.setInitialSize(conf.getInitialSize()); dataSource.setTestWhileIdle(conf.isTestWhileIdle()); dataSource.setValidationQuery(conf.getValidationQuery()); dataSource.setValidationInterval(conf.getValidationInterval()); dataSource.setMaxAge(conf.getMaxAge()); return dataSource; }