David Thornley 6 lat temu
rodzic
commit
c03b875672

+ 5
- 0
server-springboot/pom.xml Wyświetl plik

@@ -92,6 +92,11 @@
92 92
             <artifactId>jquery</artifactId>
93 93
             <version>3.1.0</version>
94 94
         </dependency>
95
+        <dependency>
96
+            <groupId>org.apache.tomcat</groupId>
97
+            <artifactId>tomcat-jdbc</artifactId>
98
+            <version>8.5.31</version>
99
+        </dependency>
95 100
     </dependencies>
96 101
 
97 102
     <build>

+ 53
- 0
server-springboot/src/main/java/com/ziplinegreen/vault/Config/DataSourceConfig.java Wyświetl plik

@@ -0,0 +1,53 @@
1
+package com.ziplinegreen.vault.Config;
2
+
3
+import org.apache.tomcat.jdbc.pool.DataSource;
4
+import org.slf4j.Logger;
5
+import org.slf4j.LoggerFactory;
6
+import org.springframework.context.annotation.Bean;
7
+import org.springframework.context.annotation.Configuration;
8
+import org.springframework.context.annotation.Profile;
9
+
10
+
11
+import java.net.URI;
12
+import java.net.URISyntaxException;
13
+
14
+@Configuration
15
+    public class DataSourceConfig {
16
+
17
+        Logger log = LoggerFactory.getLogger(getClass());
18
+
19
+        @Bean
20
+        @Profile("postgres")
21
+        public DataSource postgresDataSource() {
22
+            String databaseUrl = System.getenv("DATABASE_URL");
23
+            log.info("Initializing PostgreSQL database: {}", databaseUrl);
24
+
25
+            URI dbUri;
26
+            try {
27
+                dbUri = new URI(databaseUrl);
28
+            }
29
+            catch (URISyntaxException e) {
30
+                log.error(String.format("Invalid DATABASE_URL: %s", databaseUrl), e);
31
+                return null;
32
+            }
33
+
34
+            String username = dbUri.getUserInfo().split(":")[0];
35
+            String password = dbUri.getUserInfo().split(":")[1];
36
+            String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':'
37
+                    + dbUri.getPort() + dbUri.getPath();
38
+
39
+            org.apache.tomcat.jdbc.pool.DataSource dataSource
40
+                    = new org.apache.tomcat.jdbc.pool.DataSource();
41
+            dataSource.setDriverClassName("org.postgresql.Driver");
42
+            dataSource.setUrl(dbUrl);
43
+            dataSource.setUsername(username);
44
+            dataSource.setPassword(password);
45
+            dataSource.setTestOnBorrow(true);
46
+            dataSource.setTestWhileIdle(true);
47
+            dataSource.setTestOnReturn(true);
48
+            dataSource.setValidationQuery("SELECT 1");
49
+            return dataSource;
50
+        }
51
+
52
+    }
53
+

+ 5
- 5
server-springboot/src/main/resources/application.properties Wyświetl plik

@@ -8,12 +8,12 @@
8 8
 #spring.datasource.password=
9 9
 #spring.datasource.driver-class-name=org.h2.Driver
10 10
 
11
+spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
11 12
 
12
-
13
-spring.datasource.url= jdbc:postgres://qyobkbrdaovfvu:73068a6d3c228aab13771ff1e5398faacfbcc6733d097d4171e14f2dc92017ba@ec2-54-243-28-109.compute-1.amazonaws.com:5432/d39llklbuu4bjg
14
-spring.datasource.username=qyobkbrdaovfvu
15
-spring.datasource.password=73068a6d3c228aab13771ff1e5398faacfbcc6733d097d4171e14f2dc92017ba  
16
-spring.jpa.hibernate.ddl-auto=update
13
+#spring.datasource.url= jdbc:postgres://qyobkbrdaovfvu:73068a6d3c228aab13771ff1e5398faacfbcc6733d097d4171e14f2dc92017ba@ec2-54-243-28-109.compute-1.amazonaws.com:5432/d39llklbuu4bjg
14
+#spring.datasource.username=qyobkbrdaovfvu
15
+#spring.datasource.password=73068a6d3c228aab13771ff1e5398faacfbcc6733d097d4171e14f2dc92017ba
16
+#spring.jpa.hibernate.ddl-auto=update
17 17
 
18 18
 #spring.datasource.url=jdbc:mysql://localhost:3306/zipLine?useSSL=false
19 19
 #spring.datasource.username=root