Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method of integrating druid and configuration dependency by springboot

Shulou Source: shulou.com Published: 2022-06-02 07:36:08 09月29日 Update

The main content of this article is to explain "what is the method of springboot integrating druid and configuring dependency", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "what is the method of springboot integrating druid and configuring dependencies"?

Introduction to Druid

A large part of Java programs operate the database, and database connection pooling has to be used when operating the database to improve performance.

Druid is a database connection pool implementation on Alibaba's open source platform, which combines the advantages of DB pools such as C3P0 and DBCP, and adds log monitoring.

Druid can well monitor the execution of DB pooled connections and SQL, and is born for monitoring DB connection pooling.

Druid has deployed more than 600 applications in Alibaba and has passed the severe test of large-scale deployment in production environment for more than a year.

Spring Boot 2.0 and above use Hikari data sources by default. It can be said that both Hikari and Driud are the best data sources on Java Web. Let's focus on how Spring Boot integrates Druid data sources.

Druid official document: druid/druid-spring-boot-starter at master alibaba/druid (github.com)

Configuration dependency

Jdbc dependency, database dependency (mysql), druid dependency

Com.alibaba druid-spring-boot-starter 1.1.17 org.springframework.boot spring-boot-starter-jdbc mysql mysql-connector-java Basics-configuration Information

In application.yaml

Spring:# database datasource: url: jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&characterEncoding=utf-8 username: root password: root

Make a simple query, and the test results are shown in the figure:

Extend-configure druid monitoring featur

Under spring-datasource

Configure firewall, monitor page, and enable web monitoring

Spring:# Database datasource: url: jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&characterEncoding=utf-8 username: root password: root # druid configuration druid: # configuration Monitoring Firewall function filters: stat Wall # these two detailed parameters can be configured via filter-xxx filter: stat: enabled: true slow-sql-millis: 1000 # set 1000ms to slow query log-slow-sql: true # enable slow query monitoring wall: # here you can configure operations such as not allowing updates and deletions enabled: true # to open the monitoring page And configure the account password stat-view-servlet: enabled: true login-username: admin login-password: admin # reset-enable: false # reset button # to enable web monitoring. UrlPattern and exclusions have default values web-stat-filter: enabled: true # aop-patterns: cc.acdongla.boot.* configuration monitoring package

After starting the project, http://localhost:8080/druid/ can go to the monitoring page of druid

At this point, I believe you have a deeper understanding of "what is the method of springboot integrating druid and configuration dependence". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Configuration monitoring data database method integration query function data source Baba content firewall Ali Alibaba learning fire prevention strict excellent practical very large Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux MySQL Redmi Shulou Tech Info