Parcourir la source

【改成数据库连接池 解决经常断电导致数据库连接失败的问题】

wub il y a 2 ans
Parent
commit
f5fd423eef

+ 7 - 1
pom.xml

@@ -45,7 +45,13 @@
             <groupId>org.springframework.boot</groupId>  
             <artifactId>spring-boot-starter-data-jpa</artifactId>  
         </dependency>
-	
+
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>druid-spring-boot-starter</artifactId>
+			<version>1.2.6</version>
+		</dependency>
+
 		<dependency>
 		    <groupId>log4j</groupId>
 		    <artifactId>log4j</artifactId>

+ 2 - 5
src/main/java/com/uas/eis/UasEisApplication.java

@@ -1,18 +1,15 @@
 package com.uas.eis;
 
+import com.uas.eis.core.support.TokenPropertiesListener;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cache.annotation.EnableCaching;
-import org.springframework.context.annotation.Import;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
-import com.uas.eis.core.config.DynamicDataSourceRegister;
-import com.uas.eis.core.support.TokenPropertiesListener;
-
 @SpringBootApplication
 @EnableCaching
 @EnableScheduling
-@Import({DynamicDataSourceRegister.class})
+/*@Import({DynamicDataSourceRegister.class})*/
 public class UasEisApplication {
 	public static void main(String[] args) {
 		SpringApplication application = new SpringApplication(UasEisApplication.class);

+ 14 - 1
src/main/resources/application-prod.yml

@@ -1,10 +1,23 @@
 spring:
     datasource:
-        type: org.apache.tomcat.jdbc.pool.DataSource
+        type: com.alibaba.druid.pool.DruidDataSource
         driverClassName: oracle.jdbc.OracleDriver
         username: DATACENTER
         password: select!#%*(
         url: jdbc:oracle:thin:@172.16.0.5:1521:orcl
+        initialSize: 1
+        maxActive: 3
+        maxWait: 30000
+        testOnBorrow: false
+        testOnReturn: false
+        testWhileIdle: true
+        validationQuery: SELECT 1 FROM DUAL
+        timeBetweenEvictionRunsMillis: 60000
+        removeAbandoned: true
+        removeAbandonedTimeout: 1800
+        minEvictableIdleTimeMillis: 300000
+        poolPreparedStatements: true
+        maxPoolPreparedStatementPerConnectionSize: 3
     redis:
         host: 10.1.81.208
         port: 26379