@Bean(destroyMethod = "close") DataSource dataSource(Environment env) throws IllegalStateException, SQLException { PGPoolingDataSource pgPoolingDataSource = new PGPoolingDataSource(); pgPoolingDataSource.setUrl(env.getRequiredProperty("db.url")); pgPoolingDataSource.setUser(env.getRequiredProperty("db.username")); pgPoolingDataSource.setPassword(env.getRequiredProperty("db.password")); pgPoolingDataSource.setInitialConnections( Integer.parseInt(env.getRequiredProperty("db.pool_size"))); return pgPoolingDataSource; }
public DBConnection() { source = new PGPoolingDataSource(); // source.setDataSourceName("A Data Source"); source.setServerName(this.HOST); source.setPortNumber(this.PORT); source.setDatabaseName(this.DB); source.setUser(this.USER); source.setPassword(this.PASSWORD); // source.setMaxConnections(20);//Максимальное значение source.setInitialConnections(1); // Сколько соединений будет сразу открыто }