时间:2021-07-01 10:21:17 帮助过:20人阅读
server: # 服务配置 port: 80 # context-path: /dev spring: datasource: # 数据库连接池配置 driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/springdemo?useUnicode=true&characterEncoding=UTF-8 username: root password: asdf type: com.alibaba.druid.pool.DruidDataSource #配置监控统计拦截的filters,去掉后监控界面sql将无法统计,‘wall‘用于防火墙 filters: stat, wall, log4j #最大活跃数 maxActive: 20 #初始化数量 initialSize: 1 #最大连接等待超时时间 maxWait: 60000 #打开PSCache,并且指定每个连接PSCache的大小 poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 #通过connectionProperties属性来打开mergeSql功能;慢SQL记录 connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 1 from dual testWhileIdle: true testOnBorrow: false testOnReturn: false # filters: stat jpa: # jpa配置 hibernate: # ddl-auto: create # 会在首次启动的时候根据相应的实体类在数据库中创建相应的表,如果之前有表了,就会删掉在重建 # ddl-auto: update # 如果没有表会创建,有表会对表结构进行修改 # ddl-auto:create-drop # 应用停下来时会将表删掉 ddl-auto: none # 什么都不做(默认值) # ddl-auto: validate # 检查实体类字段和表字段是否一致,如果不一致就会报错 show-sql: true # 执行数据库操作时会打印出相应的SQL语句 # mvc: # view: # jsp文件路径设置 # prefix: /WEB-INF/jsp/ # jsp视图前缀 # suffix: .jsp # jsp视图后缀 http: multipart: # 上传文件大小设置 max-file-size: 1024Mb # 设置最大上传大小 max-request-size: 2048Mb # 设置最大请求大小 # redis: # rediss缓存设置 # host: 127.0.0.1 # 监听IP地址 # port: 6379 # 端口号 # pool: # max-idle: 20 # min-idle: 1 # max-active: 20 # max-wait: 60000 # database: 0 logging: # 日志配置 level: # cn.xiangxu.spring.controller.logger: ‘off‘ # 屏蔽掉相应包的日志控制台输出和日记文件保存View Code
package cn.xiangxu.qcbx.configuration; import com.alibaba.druid.support.http.StatViewServlet; import com.alibaba.druid.support.http.WebStatFilter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * Druid配置 */ @Configuration public class DruidConfiguration { @Bean public ServletRegistrationBean statViewServlet(){ //创建servlet注册实体 ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*"); //设置ip白名单 servletRegistrationBean.addInitParameter("allow","127.0.0.1"); //设置ip黑名单,如果allow与deny共同存在时,deny优先于allow servletRegistrationBean.addInitParameter("deny","192.168.0.19"); //设置控制台管理用户 servletRegistrationBean.addInitParameter("loginUsername","wys"); servletRegistrationBean.addInitParameter("loginPassword","123456"); //是否可以重置数据 servletRegistrationBean.addInitParameter("resetEnable","false"); return servletRegistrationBean; } @Bean public FilterRegistrationBean statFilter(){ //创建过滤器 FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter()); //设置过滤器过滤路径 filterRegistrationBean.addUrlPatterns("/*"); //忽略过滤的形式 filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); return filterRegistrationBean; } }
阿里巴巴Druid数据库连接池的使用
标签:reg code com star mini type 表结构 cti des