亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

springboot 配置DRUID數(shù)據(jù)源的方法實(shí)例分析

 更新時(shí)間:2019年12月23日 12:05:06   作者:自由港  
這篇文章主要介紹了springboot 配置DRUID數(shù)據(jù)源的方法,結(jié)合實(shí)例形式分析了springboot 配置阿里DRUID數(shù)據(jù)源的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了springboot 配置DRUID數(shù)據(jù)源的方法。分享給大家供大家參考,具體如下:

druid 是阿里開源的數(shù)據(jù)庫連接池。

開發(fā)時(shí)整合 druid 數(shù)據(jù)源過程。

1.修改pom.xml

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>druid</artifactId>
  <version>1.0.26</version>
</dependency>

增加上面的配置。

2.編輯配置數(shù)據(jù)源代碼

package com.neo.conf;
import javax.sql.DataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
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;
import org.springframework.context.annotation.PropertySource;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
@Configuration
@ConfigurationProperties(value = "classpath:druid.properties")
public class DruidConfiguration {
  @Bean(destroyMethod = "close", initMethod = "init")
  @ConfigurationProperties(prefix = "spring.datasource")
  public DataSource druidDataSource() {
    DruidDataSource druidDataSource = new DruidDataSource();
    return druidDataSource;
  }
  /**
   * 注冊(cè)一個(gè)StatViewServlet
   * @return
   */
  @Bean
  public ServletRegistrationBean druidStatViewServlet(){
    //org.springframework.boot.context.embedded.ServletRegistrationBean提供類的進(jìn)行注冊(cè).
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");
    //添加初始化參數(shù):initParams
    //白名單:
    servletRegistrationBean.addInitParameter("allow","127.0.0.1,192.168.31.77");
    //IP黑名單 (存在共同時(shí),deny優(yōu)先于allow) : 如果滿足deny的話提示:Sorry, you are not permitted to view this page.
    servletRegistrationBean.addInitParameter("deny","192.168.1.73");
    //登錄查看信息的賬號(hào)密碼.
    servletRegistrationBean.addInitParameter("loginUsername","admin");
    servletRegistrationBean.addInitParameter("loginPassword","123456");
    //是否能夠重置數(shù)據(jù).
    servletRegistrationBean.addInitParameter("resetEnable","false");
    return servletRegistrationBean;
  }
  /**
   * 注冊(cè)一個(gè):filterRegistrationBean
   * @return
   */
  @Bean
  public FilterRegistrationBean druidStatFilter(){
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
    //添加過濾規(guī)則.
    filterRegistrationBean.addUrlPatterns("/*");
    //添加不需要忽略的格式信息.
    filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
    return filterRegistrationBean;
  }
}

3.編寫配置文件 druid.properties

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mycine?useUnicode=true&characterEncoding=utf8&autoReconnect=true
spring.datasource.username=root
spring.datasource.password=root
#--------------------------
# 下面為連接池的補(bǔ)充設(shè)置,應(yīng)用到上面所有數(shù)據(jù)源中
# 初始化大小,最小,最大
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=50
# 配置獲取連接等待超時(shí)的時(shí)間
spring.datasource.maxWait=60000
# 配置間隔多久才進(jìn)行一次檢測(cè),檢測(cè)需要關(guān)閉的空閑連接,單位是毫秒
spring.datasource.timeBetweenEvictionRunsMillis=60000
# 配置一個(gè)連接在池中最小生存的時(shí)間,單位是毫秒
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
# 打開PSCache,并且指定每個(gè)連接上PSCache的大小
spring.datasource.poolPreparedStatements=false
#spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
# 配置監(jiān)控統(tǒng)計(jì)攔截的filters,去掉后監(jiān)控界面sql無法統(tǒng)計(jì),'wall'用于防火墻
#spring.datasource.filters=stat,wall,log4j
spring.datasource.filters=stat
# 通過connectProperties屬性來打開mergeSql功能;慢SQL記錄
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 合并多個(gè)DruidDataSource的監(jiān)控?cái)?shù)據(jù)
#spring.datasource.useGlobalDataSourceStat=true

4.啟動(dòng)程序查看效果

更多關(guān)于java相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Spring框架入門與進(jìn)階教程》、《Java數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Java操作DOM節(jié)點(diǎn)技巧總結(jié)》、《Java文件與目錄操作技巧匯總》和《Java緩存操作技巧匯總

希望本文所述對(duì)大家java程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Java異常 Factory method''sqlSessionFactory''rew exception;ested exception is java.lang.NoSuchMethodError:

    Java異常 Factory method''sqlSessionFactory''rew exception;este

    這篇文章主要介紹了Java異常 Factory method ‘sqlSessionFactory‘ threw exception; nested exception is java.lang.NoSuchMethodError:,本文介紹了springboot 引入mybatis-plus后報(bào)錯(cuò)的解決方案,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • spring?boot+vue實(shí)現(xiàn)JSAPI微信支付的完整步驟

    spring?boot+vue實(shí)現(xiàn)JSAPI微信支付的完整步驟

    JSAPI支付是用戶在微信中打開商戶的H5頁面,商戶在H5頁面通過調(diào)用微信支付提供的JSAPI接口調(diào)起微信支付模塊完成支付,下面這篇文章主要給大家介紹了關(guān)于spring?boot+vue實(shí)現(xiàn)JSAPI微信支付的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • Java消息隊(duì)列的簡單實(shí)現(xiàn)代碼

    Java消息隊(duì)列的簡單實(shí)現(xiàn)代碼

    本篇文章主要介紹了Java消息隊(duì)列的簡單實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-07-07
  • SpringBoot中使用AOP實(shí)現(xiàn)日志記錄功能

    SpringBoot中使用AOP實(shí)現(xiàn)日志記錄功能

    AOP的全稱是Aspect-Oriented Programming,即面向切面編程(也稱面向方面編程),它是面向?qū)ο缶幊蹋∣OP)的一種補(bǔ)充,目前已成為一種比較成熟的編程方式,本文給大家介紹了SpringBoot中使用AOP實(shí)現(xiàn)日志記錄功能,需要的朋友可以參考下
    2024-05-05
  • SpringBoot詳解實(shí)現(xiàn)自定義異常處理頁面方法

    SpringBoot詳解實(shí)現(xiàn)自定義異常處理頁面方法

    SpringBoot是Spring全家桶的成員之一,是一種整合Spring技術(shù)棧的方式(或者說是框架),同時(shí)也是簡化Spring的一種快速開發(fā)的腳手架
    2022-06-06
  • Java二叉樹路徑和代碼示例

    Java二叉樹路徑和代碼示例

    這篇文章主要介紹了Java二叉樹路徑和代碼示例,具有一定借鑒價(jià)值,需要的朋友可以參考下。
    2017-12-12
  • WeakHashMap?和?HashMap?區(qū)別及使用場(chǎng)景

    WeakHashMap?和?HashMap?區(qū)別及使用場(chǎng)景

    這篇文章主要為大家介紹了WeakHashMap?和?HashMap?的區(qū)別是什么以及何時(shí)使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • IDEA?報(bào)Plugin'maven-resources-plugin:'not?found?的解決方案

    IDEA?報(bào)Plugin'maven-resources-plugin:'not?found?

    如果在使用?IDEA?時(shí)遇到?"Plugin?'maven-resources-plugin:'?not?found"?錯(cuò)誤,可能是由于?Maven?倉庫中未找到所需的?Maven?插件,近小編給大家分享幾種解決方法,感興趣的朋友跟隨小編一起看看吧
    2023-07-07
  • hibernate4基本配置方式詳解

    hibernate4基本配置方式詳解

    這篇文章給大家?guī)砹薶ibernate4基本配置方式,非常不錯(cuò),具有參考借鑒價(jià)值,需要的額朋友參考下吧
    2017-09-09
  • java 中file.encoding的設(shè)置詳解

    java 中file.encoding的設(shè)置詳解

    這篇文章主要介紹了java 中file.encoding的設(shè)置詳解的相關(guān)資料,需要的朋友可以參考下
    2017-04-04

最新評(píng)論