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