欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot整合druid連接池的步驟

 更新時(shí)間:2020年11月28日 09:04:07   作者:熬夜禿頭選撥賽冠軍  
這篇文章主要介紹了springboot整合druid連接池的步驟,幫助大家更好的理解和學(xué)習(xí)springboot框架,感興趣的朋友可以了解下

使用springboot默認(rèn)的連接池

導(dǎo)入springboot data-jdbc依賴

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jdbc</artifactId>
    </dependency>

配置文件配置連接池

spring:
 datasource:
  username: root
  password: 5201314
  url: jdbc:mysql:///jqmb?serverTimezone=UTC
  driver-class-name: com.mysql.cj.jdbc.Driver

springboot默認(rèn)的連接池

@Autowired
   DataSource dataSource;
  @Test
  void contextLoads() {
    System.out.println(dataSource.getClass());
    System.out.println("____________________________________");
  }

使用連接池druid

導(dǎo)入druid依賴

<dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.0.18</version>
    </dependency>

配置文件配置druid的屬性

spring:
 datasource:
  username: root
  password: 5201314
  url: jdbc:mysql:///jqmb?serverTimezone=UTC
  driver-class-name: com.mysql.cj.jdbc.Driver
  type: com.alibaba.druid.pool.DruidDataSource
  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,wall,log4j
  maxPoolPreparedStatementPerConnectionSize: 20
  useGlobalDataSourceStat: true
  connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500

配置類中對(duì)druid屬性進(jìn)行綁定

@Configuration
public class DataSource_Druid_Configure {

  @ConfigurationProperties(prefix = "spring.datasource")
  @Bean
  public DruidDataSource getDataSour(){
    return new DruidDataSource();
  }

配置Druid的監(jiān)控后臺(tái)

//配置Druid的監(jiān)控
  //1、配置一個(gè)管理后臺(tái)的Servlet
  @Bean
  public ServletRegistrationBean statViewServlet(){
    ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
    Map<String,String> initParams = new HashMap<>();

    initParams.put("loginUsername","admin");//登錄用戶名
    initParams.put("loginPassword","123456");//登錄密碼
    initParams.put("allow","");//默認(rèn)就是允許所有訪問(wèn)
    initParams.put("deny","192.168.15.21");//拒絕訪問(wèn)

    bean.setInitParameters(initParams);
    return bean;
  }


  //2、配置一個(gè)web監(jiān)控的filter
  @Bean
  public FilterRegistrationBean webStatFilter(){
    FilterRegistrationBean bean = new FilterRegistrationBean();
    bean.setFilter(new WebStatFilter());
    Map<String,String> initParams = new HashMap<>();
    initParams.put("exclusions","*.js,*.css,/druid/*");
    bean.setInitParameters(initParams);
    bean.setUrlPatterns(Arrays.asList("/*"));

    return bean;
  }

訪問(wèn)http://localhost:8090/druid/login.html

如果sql監(jiān)控失效需要導(dǎo)入log4j 依賴

  <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>

以上就是springboot整合druid連接池的步驟的詳細(xì)內(nèi)容,更多關(guān)于springboot整合druid連接池的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • SpringBoot實(shí)現(xiàn)異步任務(wù)的項(xiàng)目實(shí)踐

    SpringBoot實(shí)現(xiàn)異步任務(wù)的項(xiàng)目實(shí)踐

    本文將使用SpringBoot 去實(shí)現(xiàn)異步之間的調(diào)用,提高系統(tǒng)的并發(fā)性能、用戶體驗(yàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-10-10
  • 淺談Synchronized和Lock的區(qū)別

    淺談Synchronized和Lock的區(qū)別

    這篇文章主要介紹了淺談Synchronized和Lock的區(qū)別,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-10-10
  • Spring Cloud Gateway 服務(wù)網(wǎng)關(guān)快速實(shí)現(xiàn)解析

    Spring Cloud Gateway 服務(wù)網(wǎng)關(guān)快速實(shí)現(xiàn)解析

    這篇文章主要介紹了Spring Cloud Gateway 服務(wù)網(wǎng)關(guān)快速實(shí)現(xiàn)解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-08-08
  • Java中ResultSetMetaData 元數(shù)據(jù)的具體使用

    Java中ResultSetMetaData 元數(shù)據(jù)的具體使用

    本文主要介紹了Java中ResultSetMetaData 元數(shù)據(jù)的具體使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Java重寫與重載之間的區(qū)別

    Java重寫與重載之間的區(qū)別

    本文主要介紹了Java重寫與重載之間的區(qū)別。具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-01-01
  • Java中keytool的使用

    Java中keytool的使用

    Keytool 是一個(gè)JAVA環(huán)境下的安全鑰匙與證書的管理工具,Keytool將密鑰(key)和證書(certificates)存在一個(gè)稱為keystore 的文件(受密碼保護(hù))中,本文重點(diǎn)給大家介紹keytool的使用,感興趣的朋友一起看看吧
    2022-02-02
  • Springboot如何使用Map將錯(cuò)誤提示輸出到頁(yè)面

    Springboot如何使用Map將錯(cuò)誤提示輸出到頁(yè)面

    這篇文章主要介紹了Springboot如何使用Map將錯(cuò)誤提示輸出到頁(yè)面,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • HashMap每次擴(kuò)容為什么是2倍

    HashMap每次擴(kuò)容為什么是2倍

    當(dāng)HashMap在初始化沒有指定容量的情況下,首次添加元素時(shí),數(shù)組的容量為16;當(dāng)超出閾值,數(shù)組容量為擴(kuò)容為之前的2倍,為什么HashMap每次擴(kuò)容都是之前的2倍?下面就介紹一下
    2024-11-11
  • Springboot啟動(dòng)報(bào)錯(cuò)Input length = 2的問(wèn)題解決

    Springboot啟動(dòng)報(bào)錯(cuò)Input length = 2的問(wèn)題解決

    最近使用Springboot啟動(dòng)報(bào)錯(cuò),報(bào)錯(cuò)內(nèi)容java.nio.charset.MalformedInputException: Input length = 2,下面就來(lái)介紹一下解決方法,感興趣的可以了解一下
    2024-08-08
  • SpringMVC中的@ControllerAdvice使用場(chǎng)景詳解

    SpringMVC中的@ControllerAdvice使用場(chǎng)景詳解

    這篇文章主要介紹了SpringMVC中的@ControllerAdvice使用場(chǎng)景詳解,在Spring?MVC進(jìn)行調(diào)用的過(guò)程中,會(huì)有很多的特殊的需求,比如全局異常,分頁(yè)信息和分頁(yè)搜索條件,請(qǐng)求時(shí)帶來(lái)返回時(shí)還得回顯頁(yè)面,需要的朋友可以參考下
    2024-01-01

最新評(píng)論