-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathApplication.java
More file actions
53 lines (43 loc) · 1.51 KB
/
Application.java
File metadata and controls
53 lines (43 loc) · 1.51 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package scorekeep;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.AbstractEnvironment;
@Configuration
@ComponentScan
public class Application {
enum Profile {
NODB("nodb"),
PGSQL("pgsql");
private final String name;
Profile(final String name) {
this.name = name;
}
@Override
public String toString() {
return this.name;
}
}
public static void main(String[] args) {
System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, getProfile());
SpringApplication.run(Application.class, args);
}
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static String getProfile() {
if (isRdsEnabled()) {
return Profile.PGSQL.toString();
} else {
return Profile.NODB.toString();
}
}
public static boolean isRdsEnabled() {
// Only enabled if the relevant environment variables are set
return (null != System.getenv("RDS_HOSTNAME")
&& null != System.getenv("RDS_USERNAME")
&& null != System.getenv("RDS_PASSWORD")
&& null != System.getenv("RDS_PORT"));
}
}