User-Profile-Image
hankin
  • 5
  • 首页
  • 技术-Study
    • Java
    • Php
    • WordPress
  • Enjoy-Life
  • 随拍-Photo
  • 分享-Share
  • 关于我
  • 分类
    • 随拍-Photo
    • Enjoy-Life
    • 技术-Study
    • 所有
    • 分享-Share
    • Java
    • Wordpress
    • Php
    • SQL Server
    • Linux
  • 页面
    • 首页
    • 学习日志
    • 生活日记
    • 随手拍拍
    • 关于我
  • 友链
    • 百度一下
    • 我爱水煮鱼
    • Jay's Notes
    • 淮城一只猫
    • 雨林寒舍
    • 不败君
    • 广告联盟
    • hankin
    • Tengine
    • 寥寥尘事 尘事固已矣,秉意终不迁。
    • 友人C
    • Typecho
    • jokeWorld
    • 蓝洛水深
    • 身边的大佬
    • Duilib
    • Runoob
    • Hank
Help?

Please contact us on our email for need any support

Support
    首页   ›   技术-Study   ›   Java   ›   正文
Java

DruidDataSource 德鲁伊

2021-02-17 00:39:04
313  0 0

https://mvnrepository.com/artifact/com.alibaba/druid/

运行输出结果:

Druid的部分属性值,在application.yml中添加如下

#Spring Boot 默认是不注入这些属性值的,需要自己绑定
    #druid数据源专有配置
    initialSize: 5
    minIdle: 5
    maxActive: 20
    maxWait: 60000
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
    
    #配置监控统计拦截的filters,stat:监控统计、log4j:日志记录、wall:防御sql注入
    #如果允许报错,java.lang.ClassNotFoundException: org.apache.Log4j.Properity
    #则导入log4j 依赖就行
    filters: stat,wall,log4j
    maxPoolPreparedStatementPerConnectionSize: 20
    useGlobalDataSourceStat: true
    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500

//后台监控 相当于 web.xml ServletRegistrationBean
    //因为SpringBoot 内置了 servlet容器,所以没有web.xml,替代方法:ServletRegistrationBean
    @Bean
    public ServletRegistrationBean statViewServlet(){
        ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");

        //后台需要有人登陆,账号密码配置
        HashMap<String, String> initParameters = new HashMap<>();
        //增加配置
        initParameters.put("loginUsername","admin"); //登陆key 是固定的 loginUsername loginPassword
        initParameters.put("loginPassword","123456");
        //允许谁可以访问
        initParameters.put("allow",""); //如果为空 代表所有用户都可以访问 如果写localhost表示只能本机能访问
        //禁止谁访问         initParameters.put("kuangshen","192.168.11.123");

        bean.setInitParameters(initParameters);//设置初始化参数
        return bean;
    }

//filter @Bean注入一下
    @Bean
    public FilterRegistrationBean webStatFilter(){
        FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new WebStatFilter());
        //可以过滤哪些请求?
        Map<String, String> initParameters = new HashMap<>();
        //这些东西不进行统计
        initParameters.put("exclusions","*.js,*.css,/druid/*");

        bean.setInitParameters(initParameters);
        return bean;
    }

出现log4j报错请在pom.xml配置

近期文章
  • Docsify 3分钟搭建博客
  • electron -v 全局安装,报错到晕厥
  • Electron-vue初始化项目时候报错:Command vue init requires a global addon to be installed.
  • 电脑重启后Visual Studio Code的快捷方式不存在?
  • 搜狗浏览器提示:您要访问的网站包含大量违法或违规内容
标签
0x800706be 18456 Apache bbr CDN CentOS command not found Dubbo GCE GCP google Google Cloud Platform IDEA K2 Memcached microsoft sql native client Mysql nano ODBC PB PHP phpstudy Powerbuilder Python shiro SQL2008 SQL Server Sqlite sqlite_master Sql server 2008 R2 sqlstate=08001 SSL ssr SyncPragma table thymeleaf Wordpress zookeeper 中石化,加油卡,百度地图 字段 客户端不支持加密 幽默 数据库 正则表达式 登录失败 腾讯CDN
Copyright © 2023 网站备案号: 苏ICP备18047535号
smarty_hankin 主题. Designed by hankin
主页
页面
  • 首页
  • 学习日志
  • 生活日记
  • 随手拍拍
  • 关于我
博主
_陈默默 管理员
人生就是:定性,知事,选梦,遇人,择城,终老。
125 文章 1 评论 67068 浏览
测试
测试