forked from dlizarra/spring-boot-react-webpack-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseConfig.java
53 lines (45 loc) · 1.57 KB
/
DatabaseConfig.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.dlizarra.starter;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import com.zaxxer.hikari.HikariDataSource;
@Configuration
public class DatabaseConfig {
@Profile({ StarterProfiles.STANDALONE, StarterProfiles.TEST })
@PropertySource("classpath:application-default.properties") // Not loaded by naming convention
@Configuration
static class StandaloneDatabaseConfig {
@Bean
public DataSource dataSource(final Environment env) {
final HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(env.getRequiredProperty("h2.jdbcurl"));
ds.setUsername(env.getRequiredProperty("h2.username"));
return ds;
}
}
@Profile(StarterProfiles.STAGING)
@Configuration
static class StagingDatabaseConfig {
@Bean
public DataSource dataSource(final Environment env) {
final HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(env.getRequiredProperty("psql.jdbcurl"));
ds.setUsername(env.getRequiredProperty("psql.username"));
return ds;
}
}
@Profile(StarterProfiles.PRODUCTION)
@Configuration
static class ProuctionDatabaseConfig {
@Bean
public DataSource dataSource(final Environment env) {
final HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(env.getRequiredProperty("psql.jdbcurl"));
ds.setUsername(env.getRequiredProperty("psql.username"));
return ds;
}
}
}