【整合】SpringBoot整合Druid&配置数据源监控

本文介绍了如何在SpringBoot中整合Druid数据源并配置监控。首先,文章简述了SpringBoot对数据访问层的自动配置以及JDBC的原理。接着,详细说明了如何引入Druid依赖,配置数据源以及启用监控。最后,通过访问特定URL展示了Druid监控页面的设置和SQL查询监控功能。
摘要由CSDN通过智能技术生成

SpringBoot整合Druid&配置数据源监控

1. 数据访问简介

对于数据访问层,无论是 SQL 还是 NOSQLSpringBoot 默认采用整合 Spring Data 的方式进行统一的处理
添加大量自动配置,屏蔽了很多的设置。引入各种 xxxTemplatexxxRepository 来简化我们对数据访问层的操作。
对我们来说只需要进行简单的设置即可。

2. JDBC&自动配置原理

使用 Spring Initializr 模板创建一个新的 SpringBoot 工程
需要导入的模块中,勾选出 webmysqljdbc 模块
在这里插入图片描述
pom.xml 文件依赖如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.21.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.jiker</groupId>
    <artifactId>springboot-sql</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-sql</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-bo
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值