Created
March 27, 2016 11:37
-
-
Save jampajeen/a4580bdcf1120315f653 to your computer and use it in GitHub Desktop.
Create spring datasource for SQL Server & HikariCP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver | |
jdbc.url=jdbc:sqlserver://localhost:1433;databaseName=test | |
jdbc.username=myuser | |
jdbc.password=mypass | |
hikariCP.dataSourceClassName=com.microsoft.sqlserver.jdbc.SQLServerDataSource | |
@Bean | |
public DataSource dataSource(@Value("${hikariCP.dataSourceClassName}") String dataSourceClassName, | |
@Value("${jdbc.url}") String url, | |
@Value("${jdbc.username}") String username, | |
@Value("${jdbc.password}") String password) { | |
HikariDataSource ds = new HikariDataSource(); | |
ds.setMaximumPoolSize(10); | |
ds.setDataSourceClassName(dataSourceClassName); | |
ds.addDataSourceProperty("url", url); | |
ds.addDataSourceProperty("user", username); | |
ds.addDataSourceProperty("password", password); | |
return ds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment