alibaba / druid

阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
https://github.com/alibaba/druid/wiki
Apache License 2.0
27.97k stars 8.58k forks source link

Spring Boot下如何使用druid,给出个配置介绍吧,谢谢啦 #1499

Open m949976269 opened 7 years ago

m949976269 commented 7 years ago

plz

RobinsChens commented 7 years ago

application properties

spring: datasource: name: testdb url: jdbc:mysql://172.16.5.23:3306/vp_common_config?useUnicode=true&characterEncoding=utf-8 username: root password: 'mQO7NpV1ohNjA37/xSIsNCIlVY4woR+zuAyeD3dBPpwcUX75gsZbvJftqhtpESDvItn6MUlJwrAAsi5+65fySQ=='

using druid data source

type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
maxActive: 20
initialSize: 1
maxWait: 28800
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 3000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: true
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
# encrypt password
filters: config,stat,wall,log4j
connectionProperties: "config.decrypt=true;druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000"
useGlobalDataSourceStat: true

data: mongodb: host: 172.16.45.3 port: 27017

redis: database: 0 host: 172.16.45.3

password: 'traffic.prod'

port: 6379
timeout: 30000
pool:
  max-idle: 8
  min-idle: 0
  max-active: 8
  max-wait: -1
galikaixin commented 7 years ago

我使用springboot1.4.1,发现spring.datasource. filters无法被自动配置, 打开监控页面的数据源查看,发现filters一项为空。 如果我改成javaconfig方式,@bean一个DruidDataSource并且setFilters才成功使用stat等插件。另外initialSize、maxActive...这些参数也无法被springboot设置。请问问题出在那里?

jlulimo commented 7 years ago

spring boot 哪个版本 确定连接池那些配置会生效?