需要使用Druid数据源配置的即可使用本程序。
刚用博客写的不好请谅解。
首先配置application.properties中的属性
#连接池的配置信息 # 数据库访问配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#url需要根据自己需要改
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/spring_jdbc_test_a?useUnicode=true&characterEncoding=utf-8&useSSL=false
#连接的用户名
spring.datasource.username=root
#连接的密码
spring.datasource.password=123456
# 下面为连接池的补充设置,应用到上面所有数据源中
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
# 配置获取连接等待超时的时间
spring.datasource.maxWait=60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
spring.datasource.timeBetweenEvictionRunsMillis=60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
spring.datasource.filters=stat,wall,log4j
spring.datasource.logSlowSql=true
目录情况
在pom中加入架包