Skip to content

Instantly share code, notes, and snippets.

@localghost666
Created September 12, 2018 09:06
Show Gist options
  • Save localghost666/cb9fb7b2293a34d2dfec43bde8d90945 to your computer and use it in GitHub Desktop.
Save localghost666/cb9fb7b2293a34d2dfec43bde8d90945 to your computer and use it in GitHub Desktop.
스프링 애플리케이션에서 DataSource 설정 분리
# DataSource
datasource.driver-class-name=
datasource.url=
datasource.username=
datasource.password=
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