Wednesday, 17 June 2015

Good DataSource

DriverManagerDataSource by Spring can act weird sometimes, so the best choice to use Apache data source: BasicDataSource.

Configuration:
@Bean
public DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl(JDBC_URL);
dataSource.setUsername(USERNAME);
dataSource.setPassword(PASSWORD);
dataSource.setDriverClassName(DRIVER_CLASS_NAME);
}

Maven:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1</version>
</dependency>


No comments:

Post a Comment