SpringBoot2.0+Mybatis-Plus3.0+Druid1.1.10 一站式整合

一、先快速创建一个springboot项目,其中pom.xml加入mybatis-plus 和druid需要的依赖

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> <groupId>com.kyplatform</groupId>
<artifactId>kyplatform</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>kyplatform</name>
<description>kyplatform for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!--<scope>compile</scope>-->
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>
<!--启动热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- druid-spring-boot-starter -->
<!-- <dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

二、编写application.yml文件

# DataSource Config
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource # 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
druid:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/xxxxxx?characterEncoding=utf8
username: root
password: *******
initialSize: 5
minIdle: 5
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 打开PSCache,并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
#filters: stat,wall,log4j
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 合并多个DruidDataSource的监控数据
useGlobalDataSourceStat: true
# web-stat-filter:
# enabled: false
# jsp-servlet:
# class-name: com.alibaba.druid.support.http.StatViewServlet
# init-parameters:
# loginUsername: druid
# loginPassword: druid
# Logger Config
logging:
level:
com.baomidou.mybatisplus.samples.quickstart: debug mybatis-plus:
global-config:
db-config:
db-type: MYSQL
capital-mode: false #开启大写命名
column-like: true #开启 LIKE 查询

三、接下来编写DruidConfig、DruidStatFilter、DruidStatViewServlet三个类

DruidConfig.java

package com.kyplatform.admin.config.druid;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import javax.sql.DataSource;
/**
* 配置druid需要的配置类,引入application.properties文件中以spring.datasource开头的信息
* 因此需要在application.properties文件中配置相关信息。
* @author zhicaili
*
*/ @Configuration//标识该类被纳入spring容器中实例化并管理
@ServletComponentScan //用于扫描所有的Servlet、filter、listener
public class DruidConfig {
@Bean
@ConfigurationProperties(prefix = "spring.datasource.druid")//加载时读取指定的配置信息,前缀为spring.datasource.druid
public DataSource druidDataSource(){
return new DruidDataSource();
}
}

DruidStatFilter.java

package com.kyplatform.admin.config.druid;

import com.alibaba.druid.support.http.WebStatFilter;

import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam; /**
* 配置druid过滤规则
*/
@WebFilter(
filterName="DruidWebStatFilter",
urlPatterns = "/*",
initParams = {
@WebInitParam(name = "exclusions",value="*.js,*.jpg,*.png,*.gif,*.ico,*.css,/druid/*")//配置本过滤器放行的请求后缀
}
)
public class DruidStatFilter extends WebStatFilter { }

DruidStatViewServlet.java

package com.kyplatform.admin.config.druid;

import com.alibaba.druid.support.http.StatViewServlet;

import javax.servlet.Servlet;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet; /**
* 配置druid页面配置
*/
@WebServlet(urlPatterns="/druid/*",initParams = {
@WebInitParam(name="allow",value = "127.0.0.1"),// IP白名单 (没有配置或者为空,则允许所有访问)
@WebInitParam(name = "loginUsername",value = "root"),//用户名
@WebInitParam(name = "loginPassword",value = "admin"),//密码
@WebInitParam(name = "resetEnable",value = "true")// 允许HTML页面上的“Reset All”功能
})
public class DruidStatViewServlet extends StatViewServlet implements Servlet { }

配置好后,还要在springboot的启动器类中添加@ServletComponentScan

package com.kyplatform;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Configuration; @SpringBootApplication
@ServletComponentScan
@MapperScan("com.kyplatform.admin.mapper")
public class KyplatformApplication { public static void main(String[] args) {
SpringApplication.run(KyplatformApplication.class, args);
}
}

配置好后,在浏览器中输入http://127.0.0.1:9999/项目名/druid/login.html

SpringBoot2.0+Mybatis-Plus3.0+Druid1.1.10 一站式整合的更多相关文章

  1. SpringBoot2.x+mybatis plus3.x集成Activit7版本

    最近在写一个开源项目ruoyi-vue-pro,暂时负责Activiti7工作流的搭建,接这个任务一个原因,是比较好奇Activiti7版本与先前的5.6版本究竟有什么区别,因为先前在工作当中,最开始 ...

  2. springboot2.0+mybatis多数据源集成

    最近在学springboot,把学的记录下来.主要有springboot2.0+mybatis多数据源集成,logback日志集成,springboot单元测试. 一.代码结构如下 二.pom.xml ...

  3. mybatis plus3.1.0 热加载mapper

    今天又开始写业务代码了,每次修改SQL都要重启服务,实在是浪费时间. 想起之前研究过的<mybatis plus3.1.0 热加载mapper>,一直没有成功,今天静下心来分析了问题,终于 ...

  4. spring boot:使用分布式事务seata(druid 1.1.23 / seata 1.3.0 / mybatis / spring boot 2.3.2)

    一,什么是seata? Seata:Simpe Extensible Autonomous Transcaction Architecture, 是阿里中间件开源的分布式事务解决方案. 前身是阿里的F ...

  5. Oracle数据库升级(10.2.0.4->11.2.0.4)

    环境: RHEL5.4 + Oracle 10.2.0.4 目的: 在本机将数据库升级到11.2.0.4 之前总结的Oracle数据库异机升级:http://www.cnblogs.com/jyzha ...

  6. Springboot2.0(Spring5.0)中个性化配置项目上的细节差异

    在一般的项目中,如果Spring Boot提供的Sping MVC不符合要求,则可以通过一个配置类(@Configuration)加上@EnableWebMvc注解来实现完全自己控制的MVC配置.但此 ...

  7. ffmpeg -i 10.wmv -c:v libx264 -c:a aac -strict -2 -f hls -hls_list_size 0 -hls_time 5 C:\fm\074\10\10.m3u8

    ffmpeg -i 10.wmv -c:v libx264 -c:a aac -strict -2 -f hls -hls_list_size 0 -hls_time 5 C:\fm\074\10\1 ...

  8. This Android SDK requires Android Developer Toolkit version 17.0.0 or above. Current version is 10.0.0.v201102162101-104271. Please update ADT to the latest version.

    win7/xp 下面安装Android虚拟机,更新SDK后,在Eclipse preference里指向android-sdk-windows时. 出现 : This Android SDK requ ...

  9. rake aborted! You have already activated rake 10.1.0, but your Gemfile requires rake 10.0.3. Using bundle exec may solve this.

    问题: wyy@wyy:~/moumentei-master$ rake db:createrake aborted!You have already activated rake 10.1.0, b ...

随机推荐

  1. Python- redis缓存 可达到瞬间并发量10W+

    redis是什么? mysql是一个软件,帮助开发者对一台机器的硬盘进行操作. redis是一个软件,帮助开发者对一台机器的内存进行操作. redis缓存 可达到瞬间并发量10W+ 高并发架构系列:R ...

  2. iOS -- Effective Objective-C 阅读笔记 (5)

    1: 理解 '对象等同性' 概念 理解: 根据'等同性' 来比较对象是一个非常有用的功能, 不过按照 == 操作符比较出来的结果未必是我们想要的, 因为该操作比较的是两个指针本身, 而不是其所指的对象 ...

  3. 【由浅入深理解java集合】(四)——集合 Queue

    今天我们来介绍下集合Queue中的几个重要的实现类.关于集合Queue中的内容就比较少了.主要是针对队列这种数据结构的使用来介绍Queue中的实现类. Queue用于模拟队列这种数据结构,队列通常是指 ...

  4. Java+maven+httpcomponents封装post/get请求

    httpcore4.4.10, httpclient4.5.6 package com.test.http; import com.alibaba.fastjson.JSONArray; import ...

  5. 阿里云各Linux发行版netcore兼容性评估报告---来自大石头的测试

    阿里云各Linux发行版netcore兼容性评估报告---来自大石头的测试 结论:    优先选择CentOS/Ubuntu,可选AliyunLinux(CentOS修改版)              ...

  6. vue入门知识点

    最近入坑vue 做一点小的记录 有不对的 辛苦指出 会第一时间更改上新 0.利用vue-cli构建项目新建一个目标文件夹 ,全局安装vue-cli脚手架工具 (全局安装一次即可) npm instal ...

  7. Codeforces 628F 最大流转最小割

    感觉和昨天写了的题一模一样... 这种题也能用hall定理取check, 感觉更最小割差不多. #include<bits/stdc++.h> #define LL long long # ...

  8. js事件循环机制 (Event Loop)

    一.JavaScript是单线程单并发语言 什么是单线程 主程序只有一个线程,即同一时间片断内其只能执行单个任务. 为什么选择单线程? JavaScript的主要用途是与用户互动,以及操作DOM.这决 ...

  9. Linux和window的区别

    免费与收费 最新正版Windows10官方售价¥888 Linux几乎免费(更多人愿意钻研开源软件,而收费的产品出现更多的盗版) 软件与支持 Windows平台:数量和质量的优势,补过大部分为收费软件 ...

  10. JAVA基础复习与总结<一> 对象与类的概念_内部类_继承与多态

    一.对象与类 类:类是一个模版,它描述了一类对象的行为和状态. class animal { private int color; private int size; public void eat ...