-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathDBConfig.java
More file actions
32 lines (27 loc) · 1.22 KB
/
DBConfig.java
File metadata and controls
32 lines (27 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.programmers.vouchermanagement.configuration;
import javax.sql.DataSource;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import com.programmers.vouchermanagement.configuration.profiles.DBEnabledCondition;
import com.programmers.vouchermanagement.configuration.properties.datasource.DataSourceProperties;
import com.zaxxer.hikari.HikariDataSource;
@Configuration
@Conditional(DBEnabledCondition.class)
public class DBConfig {
@Bean
public DataSource dataSource(DataSourceProperties dataSourceProperties) {
return DataSourceBuilder.create()
.url(dataSourceProperties.getUrl())
.username(dataSourceProperties.getUsername())
.password(dataSourceProperties.getPassword())
.type(HikariDataSource.class)
.build();
}
@Bean
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource dataSource) {
return new NamedParameterJdbcTemplate(dataSource);
}
}