SpringBoot整合Druid&配置数据源监控
1. 数据访问简介
对于数据访问层,无论是 SQL
还是 NOSQL
,SpringBoot
默认采用整合 Spring Data
的方式进行统一的处理
添加大量自动配置,屏蔽了很多的设置。引入各种 xxxTemplate
、xxxRepository
来简化我们对数据访问层的操作。
对我们来说只需要进行简单的设置即可。
2. JDBC&自动配置原理
使用 Spring Initializr
模板创建一个新的 SpringBoot
工程
需要导入的模块中,勾选出 web
、mysql
、jdbc
模块
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