SpringBoot-druid常用配置

开始使用

添加依赖

	   
           com.alibaba
           druid-spring-boot-starter
           1.1.16
       

常用application.properties配置

server.port=8999

spring.datasource.username=root
spring.datasource.password=root
#spring.datasource.password=E4V/8o3+gWEcJPZux53ag9FVNQJjVTn8Bhb7EbHe3O0o10R3AIreRkkHf7FW++e3DvzeDO/YcxjdCrVDkzH3Kg==
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
# 数据源配置
spring.datasource.druid.initial-size=1
spring.datasource.druid.max-active=10
spring.datasource.druid.min-idle=1
spring.datasource.druid.max-wait=60000
spring.datasource.druid.pool-prepared-statements=false
spring.datasource.druid.max-open-prepared-statements=-1
spring.datasource.druid.validation-query=SELECT 'x'
spring.datasource.druid.validation-query-timeout=-1
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.test-on-return=false
spring.datasource.druid.test-while-idle=true
spring.datasource.druid.time-between-eviction-runs-millis=60000
spring.datasource.druid.min-evictable-idle-time-millis=300000
spring.datasource.druid.max-evictable-idle-time-millis=300000
spring.datasource.druid.filters=stat,wall
spring.datasource.druid.filter.stat.log-slow-sql=true


# WebStatFilter配置,说明请参考Druid Wiki,配置_配置WebStatFilter
spring.datasource.druid.web-stat-filter.enabled= true
spring.datasource.druid.web-stat-filter.url-pattern=/*
spring.datasource.druid.web-stat-filter.exclusions="*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
spring.datasource.druid.web-stat-filter.session-stat-enable=true
spring.datasource.druid.web-stat-filter.session-stat-max-count=1000
spring.datasource.druid.web-stat-filter.principal-session-name=session_user_key
spring.datasource.druid.web-stat-filter.principal-cookie-name=cookie_user_key
spring.datasource.druid.web-stat-filter.profile-enable=true

# StatViewServlet配置,说明请参考Druid Wiki,配置_StatViewServlet配置
spring.datasource.druid.stat-view-servlet.enabled=true
spring.datasource.druid.stat-view-servlet.url-pattern=/druid/*
spring.datasource.druid.stat-view-servlet.reset-enable=false
spring.datasource.druid.stat-view-servlet.login-username=admin
spring.datasource.druid.stat-view-servlet.login-password=admin
spring.datasource.druid.stat-view-servlet.allow=
spring.datasource.druid.stat-view-servlet.deny=

#Spring监控配置,说明请参考Druid Github Wiki,配置_Druid和Spring关联监控配置
spring.datasource.druid.aop-patterns=com.fe-cred.village-doctor.controller.*

#  公钥
spring.datasource.publickey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIxeg8PbEEs+tx4Sfq0ydYgfHd+91LSaeBS4mEdxsbF1xfJ87EJBys9Fapij/UQHshnMPCk2Pjk8BUa4i1LLUlcCAwEAAQ==
#  配置 connection-properties,启用加密,配置公钥。
#spring.datasource.druid.connectionProperties=config.decrypt=true;config.decrypt.key=${spring.datasource.publickey}
# 启动ConfigFilter
spring.datasource.druid.filter.config.enabled=false

#Redis配置## Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=localhost
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=30000ms
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=1
# 连接超时时间(毫秒)
spring.redis.timeout=6000ms


#mybatis
mybatis.type-aliases-package=xyz.felix.entity
mybatis.mapper-locations=classpath:mapper/*

#pagehelper
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

# 开启swagger
swagger.enabled=true

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8

参考

官方文档
来源博客

你可能感兴趣的:(java)