Created
September 12, 2018 09:06
-
-
Save localghost666/cb9fb7b2293a34d2dfec43bde8d90945 to your computer and use it in GitHub Desktop.
스프링 애플리케이션에서 DataSource 설정 분리
This file contains 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
# DataSource | |
datasource.driver-class-name= | |
datasource.url= | |
datasource.username= | |
datasource.password= |
This file contains 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
package demo.java.app.config; | |
import com.zaxxer.hikari.HikariDataSource; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.context.annotation.PropertySource; | |
import javax.sql.DataSource; | |
@Configuration | |
@PropertySource("classpath:datasource.properties") | |
public class DataSourceConfig { | |
@Value("${datasource.driver-class-name}") | |
private String driverClassName; | |
@Value("${datasource.url}") | |
private String url; | |
@Value("${datasource.username}") | |
private String username; | |
@Value("${datasource.password}") | |
private String password; | |
@Bean | |
public DataSource dataSource() { | |
HikariDataSource dataSource = new HikariDataSource(); | |
dataSource.setDriverClassName(driverClassName); | |
dataSource.setJdbcUrl(url); | |
dataSource.setUsername(username); | |
dataSource.setPassword(password); | |
return dataSource; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment