spring boot Druid 简单的配置使用

版本准备: Spring boot :2.0.1.RELEASE
                       Druid:1.1.9



注:其实重要的就是application.properties的配置

JDBC配置

配置密码加密

publickey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIonPACL8ikgJDdYrDBbTtCx53uQSRltqkoRUAjmGJGFXVBLH6fCYq3StG5P7XzWSXAnUIKERZMxbJv0nDJOM90CAwEAAQ==
spring.datasource.druid.filter.config.enabled=true
spring.datasource.druid.connection-properties=config.decrypt=true;config.decrypt.key=${public-key}

密码加密(publickey):
找到.m2 的druid jar 包目录下执行

     java -cp druid-1.1.5.jar com.alibaba.druid.filter.config.ConfigTools your_password

基本连接

spring.datasource.druid.username=root
spring.datasource.druid.password=Xp6/DGwGHUy4ZGPxMk50OWZV8kdWCe4uWwaefk99yRADPYTG+DftoQTMab/icEIl61klSoewdwSb1PJBKOBPKA==
spring.datasource.druid.url=jdbc:mysql://localhost:3306/frame?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2b8&autoReconnect=true&useSSL=false
spring.datasource.druid.driver-class-name= com.mysql.jdbc.Driver

连接池配置,下面配置说明请参考Druid Github Wiki,配置DruidDataSource参考配置

DOC:https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter

spring.datasource.druid.initial-size=5
spring.datasource.druid.max-active=20
spring.datasource.druid.min-idle=5
spring.datasource.druid.max-wait=60000
spring.datasource.druid.pool-prepared-statements=false #在mysql下建议关闭
spring.datasource.druid.validation-query=SELECT 1 FROM DUAL
spring.datasource.druid.validation-query-timeout=120000
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.test-on-return=false
spring.datasource.druid.test-while-idle=true

wall,log4j

spring.datasource.druid.filters=stat,wall,log4j2

配置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,*.png,*.css,*.ico,/druid/*,/static/*
spring.datasource.druid.web-stat-filter.session-stat-enable=false
spring.datasource.druid.web-stat-filter.session-stat-max-count=1000
spring.datasource.druid.web-stat-filter.profile-enable=true

慢sql

spring.datasource.druid.filter.stat.enabled=true
spring.datasource.druid.filter.stat.db-type=mysql
spring.datasource.druid.filter.stat.log-slow-sql=true
spring.datasource.druid.filter.stat.slow-sql-millis=2000
spring.datasource.druid.filter.stat.merge-sql=true

spring.datasource.druid.filter.log4j2.enabled=true
spring.datasource.druid.filter.log4j2.connection-log-enabled=false
spring.datasource.druid.filter.log4j2.statement-create-after-log-enabled=false
spring.datasource.druid.filter.log4j2.statement-close-after-log-enabled=false
spring.datasource.druid.filter.log4j2.result-set-open-after-log-enabled=false
spring.datasource.druid.filter.log4j2.result-set-close-after-log-enabled=false
spring.datasource.druid.filter.log4j2.statement-execute-query-after-log-enabled=false

配置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=true
spring.datasource.druid.stat-view-servlet.login-username=root
spring.datasource.druid.stat-view-servlet.login-password=root

每天把监控数据输出到日志中

spring.datasource.druid.time-between-log-stats-millis=86400000

配置Druid和Spring关联监控配置(Spring监控AOP切入点,如x.y.z.ser.*,配置多个英文逗号分隔)

spring.datasource.druid.aop-patterns= com.xinaml.frame.ser.*

如果spring.datasource.druid.aop-patterns要代理的类没有定义interface请设置:

spring.aop.proxy-target-class=true
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值