Skip to content

Instantly share code, notes, and snippets.

@przodownikR1
Created July 21, 2015 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save przodownikR1/629f3444d2b3a3399b9a to your computer and use it in GitHub Desktop.
Save przodownikR1/629f3444d2b3a3399b9a to your computer and use it in GitHub Desktop.
example create datasource in javaConfig with full desc and params
@Bean
public DataSource dataSource() {
final DataSource dataSource = new DataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl(env.getProperty("jdbc.url"));
dataSource.setUsername(env.getProperty("jdbc.username"));
dataSource.setPassword(env.getProperty("jdbc.password"));
dataSource.setTestOnBorrow(true);
dataSource.setTestWhileIdle(true);
dataSource.setTestOnReturn(false);
dataSource.setValidationQuery("SELECT 1");
dataSource.setValidationInterval(30000);
dataSource.setTimeBetweenEvictionRunsMillis(5000);
dataSource.setMaxActive(100);
dataSource.setMinIdle(10);
dataSource.setMaxWait(10000);
dataSource.setInitialSize(10);
dataSource.setRemoveAbandonedTimeout(3600);
dataSource.setRemoveAbandoned(true);
dataSource.setLogAbandoned(true);
dataSource.setMinEvictableIdleTimeMillis(30000);
return dataSource;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment