Переглянути джерело

修改数据库连接池为druid

lighter 1 рік тому
батько
коміт
94c35528af

+ 6 - 0
pom.xml

@@ -15,6 +15,7 @@
     <description>server for yibao-web</description>
     <properties>
         <java.version>1.8</java.version>
+        <druid.version>1.1.10</druid.version>
     </properties>
     <dependencies>
         <!--工具类        -->
@@ -31,6 +32,11 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-websocket</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid-spring-boot-starter</artifactId>
+            <version>1.1.20</version>
+        </dependency>
         <!-- 肖蟾 使用mybatis-plus-->
         <dependency>
             <groupId>com.baomidou</groupId>

+ 38 - 11
src/main/resources/application-dev.yml

@@ -22,28 +22,55 @@ spring:
           url: "jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb"
           username: "sa"
           password:
-          type: "com.zaxxer.hikari.HikariDataSource"
           driver-class-name: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
         lis:
           url: "jdbc:sqlserver://172.16.32.178:1433;databaseName=eLimsCore"
           username: "sa"
           password: "hnthxyyy"
-          type: "com.zaxxer.hikari.HikariDataSource"
           driver-class-name: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
         dev:
           url: "jdbc:sqlserver://172.16.32.179:1433;databaseName=thxyhisdb"
           username: "sa"
           password:
-          type: "com.zaxxer.hikari.HikariDataSource"
           driver-class-name: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
-    hikari:
-      minimum-idle: 10
-      idle-timeout: 180000
-      maximum-pool-size: 30
-      auto-commit: true
-      pool-name: lisDbPool
-      connection-timeout: 30000
-      connection-test-query: select 1
+    durid:
+      #type: com.alibaba.druid.pool.DruidDataSource
+      #初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时
+      initial-size: 40
+      #最大连接池数量
+      max-active: 100
+      #最小连接池数量
+      min-idle: 40
+      #获取连接时最大等待时间,单位毫秒
+      max-wait: 60000
+      #使用非公平锁。
+      use-unfair-lock: true
+      #用来检测连接是否有效的sql,要求是一个查询语句。
+      validation-query: SELECT 1
+      #建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
+      test-while-idle: true
+      #申请连接时执行validationQuery检测连接是否有效,
+      test-on-borrow: true
+      #归还连接时执行validationQuery检测连接是否有效,
+      test-on-return: false
+      #Destroy线程会检测连接的间隔时间,testWhileIdle的判断依据,详细看testWhileIdle属性的说明
+      time-between-eviction-runs-millis: 60000
+      #配置一个连接在池中最小生存的时间,单位是毫秒
+      min-evictable-idle-time-millis: 300000
+      #监控统计用的filter:stat  日志用的filter:log4j    防御sql注入的filter:wall
+      filters: stat
+      #是否缓存preparedStatement,也就是PSCache,在mysql5.5以下的版本中没有PSCache功能,建议关闭掉
+      pool-prepared-statements: false
+      #要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。
+      max-pool-prepared-statement-per-connection-size: 200
+      #对于长时间不使用的连接强制关闭
+      remove-abandoned: true
+      #数据库链接超过180秒开始关闭空闲连接 秒为单位
+      remove-abandoned-timeout: 180
+      #将当前关闭动作记录到日志  此配置项会影响性能,只在排查的时候打开,系统运行时最好关闭。
+      log-abandoned: true
+  autoconfigure:
+    exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 去除druid配置
   jackson:
     time-zone: Asia/Shanghai
     date-format: yyyy-MM-dd HH:mm:ss

+ 39 - 16
src/main/resources/application-prod.yml

@@ -19,29 +19,52 @@ spring:
           url: "jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb"
           username: "sa"
           password:
-          type: "com.zaxxer.hikari.HikariDataSource"
           driver-class-name: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
         lis:
           url: "jdbc:sqlserver://172.16.32.178:1433;databaseName=eLimsCore"
           username: "sa"
           password: "hnthxyyy"
-          type: "com.zaxxer.hikari.HikariDataSource"
           driver-class-name: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
-    hikari:
-      minimum-idle: 10
-      idle-timeout: 180000
-      maximum-pool-size: 300
-      auto-commit: true
-      pool-name: lisDbPool
-      connection-timeout: 30000
-      connection-test-query: select 1
-  #  rabbitmq:
-  #    host: 192.168.200.3
-  #    port: 5672
-  #    username: dj
-  #    password: 123456
+    durid:
+      #type: com.alibaba.druid.pool.DruidDataSource
+      #初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时
+      initial-size: 40
+      #最大连接池数量
+      max-active: 100
+      #最小连接池数量
+      min-idle: 40
+      #获取连接时最大等待时间,单位毫秒
+      max-wait: 60000
+      #使用非公平锁。
+      use-unfair-lock: true
+      #用来检测连接是否有效的sql,要求是一个查询语句。
+      validation-query: SELECT 1
+      #建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
+      test-while-idle: true
+      #申请连接时执行validationQuery检测连接是否有效,
+      test-on-borrow: true
+      #归还连接时执行validationQuery检测连接是否有效,
+      test-on-return: false
+      #Destroy线程会检测连接的间隔时间,testWhileIdle的判断依据,详细看testWhileIdle属性的说明
+      time-between-eviction-runs-millis: 60000
+      #配置一个连接在池中最小生存的时间,单位是毫秒
+      min-evictable-idle-time-millis: 300000
+      #监控统计用的filter:stat  日志用的filter:log4j    防御sql注入的filter:wall
+      filters: stat
+      #是否缓存preparedStatement,也就是PSCache,在mysql5.5以下的版本中没有PSCache功能,建议关闭掉
+      pool-prepared-statements: false
+      #要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。
+      max-pool-prepared-statement-per-connection-size: 200
+      #对于长时间不使用的连接强制关闭
+      remove-abandoned: true
+      #数据库链接超过180秒开始关闭空闲连接 秒为单位
+      remove-abandoned-timeout: 180
+      #将当前关闭动作记录到日志  此配置项会影响性能,只在排查的时候打开,系统运行时最好关闭。
+      log-abandoned: true
+  autoconfigure:
+    exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 去除druid配置
   jackson:
-    time-zone: GMT+8
+    time-zone: Asia/Shanghai
     date-format: yyyy-MM-dd HH:mm:ss
   mvc:
     format:

+ 38 - 10
src/main/resources/application-show.yml

@@ -22,22 +22,50 @@ spring:
           url: "jdbc:sqlserver://172.16.32.179:1433;databaseName=thxyhisdb"
           username: "sa"
           password:
-          type: "com.zaxxer.hikari.HikariDataSource"
           driver-class-name: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
         lis:
           url: "jdbc:sqlserver://172.16.32.178:1433;databaseName=eLimsCore"
           username: "sa"
           password: "hnthxyyy"
-          type: "com.zaxxer.hikari.HikariDataSource"
           driver-class-name: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
-    hikari:
-      minimum-idle: 10
-      idle-timeout: 180000
-      maximum-pool-size: 30
-      auto-commit: true
-      pool-name: lisDbPool
-      connection-timeout: 30000
-      connection-test-query: select 1
+    durid:
+      #type: com.alibaba.druid.pool.DruidDataSource
+      #初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时
+      initial-size: 40
+      #最大连接池数量
+      max-active: 100
+      #最小连接池数量
+      min-idle: 40
+      #获取连接时最大等待时间,单位毫秒
+      max-wait: 60000
+      #使用非公平锁。
+      use-unfair-lock: true
+      #用来检测连接是否有效的sql,要求是一个查询语句。
+      validation-query: SELECT 1
+      #建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
+      test-while-idle: true
+      #申请连接时执行validationQuery检测连接是否有效,
+      test-on-borrow: true
+      #归还连接时执行validationQuery检测连接是否有效,
+      test-on-return: false
+      #Destroy线程会检测连接的间隔时间,testWhileIdle的判断依据,详细看testWhileIdle属性的说明
+      time-between-eviction-runs-millis: 60000
+      #配置一个连接在池中最小生存的时间,单位是毫秒
+      min-evictable-idle-time-millis: 300000
+      #监控统计用的filter:stat  日志用的filter:log4j    防御sql注入的filter:wall
+      filters: stat
+      #是否缓存preparedStatement,也就是PSCache,在mysql5.5以下的版本中没有PSCache功能,建议关闭掉
+      pool-prepared-statements: false
+      #要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。
+      max-pool-prepared-statement-per-connection-size: 200
+      #对于长时间不使用的连接强制关闭
+      remove-abandoned: true
+      #数据库链接超过180秒开始关闭空闲连接 秒为单位
+      remove-abandoned-timeout: 180
+      #将当前关闭动作记录到日志  此配置项会影响性能,只在排查的时候打开,系统运行时最好关闭。
+      log-abandoned: true
+  autoconfigure:
+    exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 去除druid配置
   jackson:
     time-zone: Asia/Shanghai
     date-format: yyyy-MM-dd HH:mm:ss

+ 41 - 14
src/main/resources/application.yml

@@ -15,35 +15,62 @@ spring:
     cache: false
   datasource:
     dynamic:
-      primary: his
+      primary: dev
       strict: false
       datasource:
         his:
           url: "jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb"
           username: "sa"
           password:
-          type: "com.zaxxer.hikari.HikariDataSource"
           driver-class-name: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
         lis:
           url: "jdbc:sqlserver://172.16.32.178:1433;databaseName=eLimsCore"
           username: "sa"
           password: "hnthxyyy"
-          type: "com.zaxxer.hikari.HikariDataSource"
           driver-class-name: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
         dev:
           url: "jdbc:sqlserver://172.16.32.179:1433;databaseName=thxyhisdb"
           username: "sa"
           password:
-          type: "com.zaxxer.hikari.HikariDataSource"
           driver-class-name: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
-    hikari:
-      minimum-idle: 10
-      idle-timeout: 180000
-      maximum-pool-size: 300
-      auto-commit: true
-      pool-name: lisDbPool
-      connection-timeout: 30000
-      connection-test-query: select 1
+    durid:
+      #type: com.alibaba.druid.pool.DruidDataSource
+      #初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时
+      initial-size: 40
+      #最大连接池数量
+      max-active: 100
+      #最小连接池数量
+      min-idle: 40
+      #获取连接时最大等待时间,单位毫秒
+      max-wait: 60000
+      #使用非公平锁。
+      use-unfair-lock: true
+      #用来检测连接是否有效的sql,要求是一个查询语句。
+      validation-query: SELECT 1
+      #建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
+      test-while-idle: true
+      #申请连接时执行validationQuery检测连接是否有效,
+      test-on-borrow: true
+      #归还连接时执行validationQuery检测连接是否有效,
+      test-on-return: false
+      #Destroy线程会检测连接的间隔时间,testWhileIdle的判断依据,详细看testWhileIdle属性的说明
+      time-between-eviction-runs-millis: 60000
+      #配置一个连接在池中最小生存的时间,单位是毫秒
+      min-evictable-idle-time-millis: 300000
+      #监控统计用的filter:stat  日志用的filter:log4j    防御sql注入的filter:wall
+      filters: stat
+      #是否缓存preparedStatement,也就是PSCache,在mysql5.5以下的版本中没有PSCache功能,建议关闭掉
+      pool-prepared-statements: false
+      #要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。
+      max-pool-prepared-statement-per-connection-size: 200
+      #对于长时间不使用的连接强制关闭
+      remove-abandoned: true
+      #数据库链接超过180秒开始关闭空闲连接 秒为单位
+      remove-abandoned-timeout: 180
+      #将当前关闭动作记录到日志  此配置项会影响性能,只在排查的时候打开,系统运行时最好关闭。
+      log-abandoned: true
+  autoconfigure:
+    exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 去除druid配置
   jackson:
     time-zone: Asia/Shanghai
     date-format: yyyy-MM-dd HH:mm:ss
@@ -76,7 +103,7 @@ si-secret-key: SK3Oip3a2R3NLz2xm58Mpmi69oFu96KrdKNRKglN
 si-zy-fee-url: http://172.16.32.166:1000
 si-mz-fee-url: http://172.16.32.166:1100/mzFee
 si-injury-fee-url: http://172.16.32.163:2100/siInjury
-si-injury-systm-url: http://172.16.32.163:2000/siInjury
+#si-injury-systm-url: http://172.16.32.163:2000/siInjury
 thmz-api-url: http://172.16.32.160:81/thmz/api/v1
 
 
@@ -87,7 +114,7 @@ thmz-api-url: http://172.16.32.160:81/thmz/api/v1
 #si-zy-fee-url: http://localhost:1000
 #si-mz-fee-url: http://localhost:1100/mzFee
 #si-injury-fee-url: http://localhost:2100/siInjury
-#si-injury-systm-url: http://localhost:2000/siInjury
+si-injury-systm-url: http://localhost:2000/siInjury
 #thmz-api-url: http://172.16.30.33:81/thmz/api/v1
 
 #logging: