@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;
  }
Exemplo n.º 2
0
  @Bean(destroyMethod = "close")
  public DataSource dataSource() {
    DataSource dataSource = new DataSource();
    dataSource.setUrl(url);
    dataSource.setDriverClassName(driverClassName);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setDefaultAutoCommit(defaultAutoCommit);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setValidationInterval(validationInterval);
    dataSource.setTestWhileIdle(testWhileIdle);
    dataSource.setLogAbandoned(logAbandoned);
    dataSource.setRemoveAbandoned(removeAbandoned);
    dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout);

    return dataSource;
  }
Exemplo n.º 3
0
  @Bean
  public DataSource dataSource() {
    String[] userInfo = databaseUri.getUserInfo().split(":");

    DataSource dataSource = new DataSource();
    dataSource.setDriverClassName("org.postgresql.Driver");
    dataSource.setUrl(
        String.format("jdbc:postgresql://%s%s", databaseUri.getHost(), databaseUri.getPath()));
    dataSource.setUsername(userInfo[0]);
    dataSource.setPassword(userInfo[1]);
    dataSource.setMinIdle(10);
    dataSource.setMaxActive(200);
    dataSource.setTestOnBorrow(true);
    dataSource.setTestOnReturn(true);
    dataSource.setTestWhileIdle(true);
    dataSource.setRemoveAbandoned(true);
    dataSource.setRemoveAbandonedTimeout(300);
    dataSource.setMaxWait(5000);
    dataSource.setValidationQuery("SELECT 1 FROM DUAL");
    dataSource.setTimeBetweenEvictionRunsMillis(1800000);
    dataSource.setNumTestsPerEvictionRun(3);
    dataSource.setMinEvictableIdleTimeMillis(1800000);
    return dataSource;
  }