Commit 6c969a63dd17d30efc1ef13adc46893798df2601
1 parent
3227dcd0
去除druid数据库连接池,使用spring支持的hikari
Showing
6 changed files
with
11 additions
and
131 deletions
pom.xml
| @@ -123,11 +123,9 @@ | @@ -123,11 +123,9 @@ | ||
| 123 | <artifactId>spring-boot-starter-security</artifactId> | 123 | <artifactId>spring-boot-starter-security</artifactId> |
| 124 | </dependency> | 124 | </dependency> |
| 125 | 125 | ||
| 126 | - <!-- druid数据库连接池 --> | ||
| 127 | <dependency> | 126 | <dependency> |
| 128 | - <groupId>com.alibaba</groupId> | ||
| 129 | - <artifactId>druid-spring-boot-starter</artifactId> | ||
| 130 | - <version>1.2.11</version> | 127 | + <groupId>org.springframework.boot</groupId> |
| 128 | + <artifactId>spring-boot-starter-jdbc</artifactId> | ||
| 131 | </dependency> | 129 | </dependency> |
| 132 | 130 | ||
| 133 | <!-- mysql数据库 --> | 131 | <!-- mysql数据库 --> |
| @@ -294,7 +292,7 @@ | @@ -294,7 +292,7 @@ | ||
| 294 | <plugin> | 292 | <plugin> |
| 295 | <groupId>org.springframework.boot</groupId> | 293 | <groupId>org.springframework.boot</groupId> |
| 296 | <artifactId>spring-boot-maven-plugin</artifactId> | 294 | <artifactId>spring-boot-maven-plugin</artifactId> |
| 297 | - <version>2.3.5.RELEASE</version> | 295 | + <version>2.7.2</version> |
| 298 | <configuration> | 296 | <configuration> |
| 299 | <includeSystemScope>true</includeSystemScope> | 297 | <includeSystemScope>true</includeSystemScope> |
| 300 | </configuration> | 298 | </configuration> |
src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
| 1 | package com.genersoft.iot.vmp; | 1 | package com.genersoft.iot.vmp; |
| 2 | 2 | ||
| 3 | -import com.genersoft.iot.vmp.conf.druid.EnableDruidSupport; | ||
| 4 | import com.genersoft.iot.vmp.utils.GitUtil; | 3 | import com.genersoft.iot.vmp.utils.GitUtil; |
| 5 | import com.genersoft.iot.vmp.utils.SpringBeanFactory; | 4 | import com.genersoft.iot.vmp.utils.SpringBeanFactory; |
| 6 | import org.slf4j.Logger; | 5 | import org.slf4j.Logger; |
| @@ -25,7 +24,6 @@ import java.util.Collections; | @@ -25,7 +24,6 @@ import java.util.Collections; | ||
| 25 | @ServletComponentScan("com.genersoft.iot.vmp.conf") | 24 | @ServletComponentScan("com.genersoft.iot.vmp.conf") |
| 26 | @SpringBootApplication | 25 | @SpringBootApplication |
| 27 | @EnableScheduling | 26 | @EnableScheduling |
| 28 | -@EnableDruidSupport | ||
| 29 | public class VManageBootstrap extends SpringBootServletInitializer { | 27 | public class VManageBootstrap extends SpringBootServletInitializer { |
| 30 | 28 | ||
| 31 | private final static Logger logger = LoggerFactory.getLogger(VManageBootstrap.class); | 29 | private final static Logger logger = LoggerFactory.getLogger(VManageBootstrap.class); |
src/main/java/com/genersoft/iot/vmp/conf/GlobalResponseAdvice.java
| @@ -10,14 +10,11 @@ import org.springframework.context.annotation.Bean; | @@ -10,14 +10,11 @@ import org.springframework.context.annotation.Bean; | ||
| 10 | import org.springframework.core.MethodParameter; | 10 | import org.springframework.core.MethodParameter; |
| 11 | import org.springframework.http.MediaType; | 11 | import org.springframework.http.MediaType; |
| 12 | import org.springframework.http.converter.HttpMessageConverter; | 12 | import org.springframework.http.converter.HttpMessageConverter; |
| 13 | -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
| 14 | import org.springframework.http.server.ServerHttpRequest; | 13 | import org.springframework.http.server.ServerHttpRequest; |
| 15 | import org.springframework.http.server.ServerHttpResponse; | 14 | import org.springframework.http.server.ServerHttpResponse; |
| 16 | import org.springframework.web.bind.annotation.RestControllerAdvice; | 15 | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| 17 | import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; | 16 | import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; |
| 18 | 17 | ||
| 19 | -import java.util.List; | ||
| 20 | - | ||
| 21 | /** | 18 | /** |
| 22 | * 全局统一返回结果 | 19 | * 全局统一返回结果 |
| 23 | * @author lin | 20 | * @author lin |
| @@ -63,7 +60,7 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> { | @@ -63,7 +60,7 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> { | ||
| 63 | * @return | 60 | * @return |
| 64 | */ | 61 | */ |
| 65 | @Bean | 62 | @Bean |
| 66 | - public HttpMessageConverters custHttpMessageConverter() { | 63 | + public HttpMessageConverters fast() { |
| 67 | return new HttpMessageConverters(new FastJsonHttpMessageConverter()); | 64 | return new HttpMessageConverters(new FastJsonHttpMessageConverter()); |
| 68 | } | 65 | } |
| 69 | } | 66 | } |
src/main/java/com/genersoft/iot/vmp/conf/druid/DruidConfiguration.java deleted
100644 → 0
| 1 | -package com.genersoft.iot.vmp.conf.druid; | ||
| 2 | - | ||
| 3 | -import com.alibaba.druid.support.http.StatViewServlet; | ||
| 4 | -import com.alibaba.druid.support.http.WebStatFilter; | ||
| 5 | -import org.springframework.beans.factory.annotation.Value; | ||
| 6 | -import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
| 7 | -import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
| 8 | -import org.springframework.context.annotation.Bean; | ||
| 9 | - | ||
| 10 | -import javax.servlet.Filter; | ||
| 11 | -import javax.servlet.Servlet; | ||
| 12 | - | ||
| 13 | -/** | ||
| 14 | - * druid监控配置 | ||
| 15 | - * @author | ||
| 16 | - */ | ||
| 17 | -public class DruidConfiguration { | ||
| 18 | - | ||
| 19 | - @Value("${rj-druid-manage.allow:127.0.0.1}") | ||
| 20 | - private String allow; | ||
| 21 | - | ||
| 22 | - @Value("${rj-druid-manage.deny:}") | ||
| 23 | - private String deny; | ||
| 24 | - | ||
| 25 | - @Value("${rj-druid-manage.loginUsername:admin}") | ||
| 26 | - private String loginUsername; | ||
| 27 | - | ||
| 28 | - @Value("${rj-druid-manage.loginPassword:admin}") | ||
| 29 | - private String loginPassword; | ||
| 30 | - | ||
| 31 | - @Value("${rj-druid-manage.resetEnable:false}") | ||
| 32 | - private String resetEnable; | ||
| 33 | - | ||
| 34 | - /** | ||
| 35 | - * druid监控页面开启 | ||
| 36 | - */ | ||
| 37 | - @Bean | ||
| 38 | - public ServletRegistrationBean druidServlet() { | ||
| 39 | - ServletRegistrationBean<Servlet> servletRegistrationBean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*"); | ||
| 40 | - // IP白名单 | ||
| 41 | - servletRegistrationBean.addInitParameter("allow", allow); | ||
| 42 | - // IP黑名单(共同存在时,deny优先于allow) | ||
| 43 | - servletRegistrationBean.addInitParameter("deny", deny); | ||
| 44 | - //控制台管理用户 | ||
| 45 | - servletRegistrationBean.addInitParameter("loginUsername", loginUsername); | ||
| 46 | - servletRegistrationBean.addInitParameter("loginPassword", loginPassword); | ||
| 47 | - //是否能够重置数据 禁用HTML页面上的“Reset All”功能 | ||
| 48 | - servletRegistrationBean.addInitParameter("resetEnable", resetEnable); | ||
| 49 | - return servletRegistrationBean; | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - /** | ||
| 53 | - * druid url监控配置 | ||
| 54 | - */ | ||
| 55 | - @Bean | ||
| 56 | - public FilterRegistrationBean filterRegistrationBean() { | ||
| 57 | - FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>(new WebStatFilter()); | ||
| 58 | - filterRegistrationBean.addUrlPatterns("/*"); | ||
| 59 | - filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); | ||
| 60 | - return filterRegistrationBean; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - | ||
| 64 | -} | ||
| 65 | \ No newline at end of file | 0 | \ No newline at end of file |
src/main/java/com/genersoft/iot/vmp/conf/druid/EnableDruidSupport.java deleted
100644 → 0
| 1 | -package com.genersoft.iot.vmp.conf.druid; | ||
| 2 | - | ||
| 3 | -import org.springframework.boot.web.servlet.ServletComponentScan; | ||
| 4 | -import org.springframework.context.annotation.Import; | ||
| 5 | - | ||
| 6 | -import java.lang.annotation.*; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * druid监控支持注解 | ||
| 10 | - * | ||
| 11 | - * @author | ||
| 12 | - * {@link DruidConfiguration} druid监控页面安全配置支持 | ||
| 13 | - * {@link ServletComponentScan} druid监控页面需要扫描servlet | ||
| 14 | - */ | ||
| 15 | -@Target(ElementType.TYPE) | ||
| 16 | -@Retention(RetentionPolicy.RUNTIME) | ||
| 17 | -@Documented | ||
| 18 | -@Inherited | ||
| 19 | -@Import({ | ||
| 20 | - DruidConfiguration.class, | ||
| 21 | -}) | ||
| 22 | -@ServletComponentScan | ||
| 23 | -public @interface EnableDruidSupport { | ||
| 24 | -} |
src/main/resources/all-application.yml
| @@ -30,44 +30,19 @@ spring: | @@ -30,44 +30,19 @@ spring: | ||
| 30 | poolMaxWait: 5 | 30 | poolMaxWait: 5 |
| 31 | # [必选] jdbc数据库配置 | 31 | # [必选] jdbc数据库配置 |
| 32 | datasource: | 32 | datasource: |
| 33 | - type: com.alibaba.druid.pool.DruidDataSource | 33 | + type: com.zaxxer.hikari.HikariDataSource |
| 34 | driver-class-name: com.mysql.cj.jdbc.Driver | 34 | driver-class-name: com.mysql.cj.jdbc.Driver |
| 35 | url: jdbc:mysql://127.0.0.1:3306/wvp2?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true | 35 | url: jdbc:mysql://127.0.0.1:3306/wvp2?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true |
| 36 | username: root | 36 | username: root |
| 37 | password: root123 | 37 | password: root123 |
| 38 | - druid: | 38 | + hikari: |
| 39 | + connection-timeout: 20000 # 是客户端等待连接池连接的最大毫秒数 | ||
| 39 | initialSize: 10 # 连接池初始化连接数 | 40 | initialSize: 10 # 连接池初始化连接数 |
| 40 | - maxActive: 200 # 连接池最大连接数 | ||
| 41 | - minIdle: 5 # 连接池最小空闲连接数 | ||
| 42 | - maxWait: 60000 # 获取连接时最大等待时间,单位毫秒。配置了maxWait之后,缺省启用公平锁,并发效率会有所下降,如果需要可以通过配置useUnfairLock属性为true使用非公平锁。 | ||
| 43 | - keepAlive: true # 连接池中的minIdle数量以内的连接,空闲时间超过minEvictableIdleTimeMillis,则会执行keepAlive操作。 | ||
| 44 | - validationQuery: select 1 # 检测连接是否有效sql,要求是查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用。 | ||
| 45 | - testWhileIdle: true # 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 | ||
| 46 | - testOnBorrow: false # 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 | ||
| 47 | - testOnReturn: false # 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 | ||
| 48 | - poolPreparedStatements: false # 是否開啟PSCache,並且指定每個連線上PSCache的大小 | ||
| 49 | - timeBetweenEvictionRunsMillis: 60000 # 配置間隔多久才進行一次檢測,檢測需要關閉的空閒連線,單位是毫秒 | ||
| 50 | - minEvictableIdleTimeMillis: 300000 # 配置一個連線在池中最小生存的時間,單位是毫秒 | ||
| 51 | - filters: stat,slf4j # 配置监控统计拦截的filters,监控统计用的filter:sta, 日志用的filter:log4j | ||
| 52 | - useGlobalDataSourceStat: true # 合并多个DruidDataSource的监控数据 | ||
| 53 | - # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 | ||
| 54 | - connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=1000 | ||
| 55 | - #stat-view-servlet.url-pattern: /admin/druid/* | 41 | + maximum-pool-size: 200 # 连接池最大连接数 |
| 42 | + minimum-idle: 5 # 连接池最小空闲连接数 | ||
| 43 | + idle-timeout: 300000 # 允许连接在连接池中空闲的最长时间(以毫秒为单位) | ||
| 44 | + max-lifetime: 1200000 # 是池中连接关闭后的最长生命周期(以毫秒为单位) | ||
| 56 | 45 | ||
| 57 | -# druid管理监控页面的一些配置 | ||
| 58 | -rj-druid-manage: | ||
| 59 | - allow: # 访问druid监控页面的IP白名单 | ||
| 60 | - deny: 192.168.1.100 # 访问druid监控页面IP黑名单 | ||
| 61 | - loginUsername: rjAdmin # 访问druid监控页面账号 | ||
| 62 | - loginPassword: rj@2022 # 访问druid监控页面密码 | ||
| 63 | - | ||
| 64 | -#mybatis: | ||
| 65 | -# configuration: | ||
| 66 | -# # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 | ||
| 67 | -# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl | ||
| 68 | -# # 返回类型为Map,显示null对应的字段 | ||
| 69 | -# call-setters-on-nulls: true | ||
| 70 | -## [可选] WVP监听的HTTP端口, 网页和接口调用都是这个端口 | ||
| 71 | 46 | ||
| 72 | # [可选] WVP监听的HTTP端口, 网页和接口调用都是这个端口 | 47 | # [可选] WVP监听的HTTP端口, 网页和接口调用都是这个端口 |
| 73 | server: | 48 | server: |