SpringBoot 框架整合
一、主要思路
- 使用spring-boot-starter-jdbc集成Mybatis框架
- 通过spring-boot-starter-cache集成EhCache
- 使用WebServlet集成Druid监控
二、程序实现
1. POM 文件
<?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.geek</groupId>
<artifactId>SpringBootInit</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<properties>
<mybatis.version>3.4.5</mybatis.version>
<mybatis.spring.version>1.3.1</mybatis.spring.version>
<druid.version>1.1.6</druid.version>
<ehcache.version>3.4.0</ehcache.version>
<mysql.connector.version>5.1.45</mysql.connector.version>
</properties>
<dependencies>
<!-- SpringBoot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<!-- Mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.version}</version>
</dependency>
<!-- MySQL Druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- EhCache -->
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
</dependencies>
</project>
2. 集成Mybatis
mybatis:
mapper-locations: classpath:mappers/*.xml
type-aliases-package: com.geek.*.dto
3. 集成EhCache
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
<defaultCache
eternal="false"
maxElementsInMemory="1000"
overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LRU"/>
<cache
name="users"
eternal="false"
maxElementsInMemory="100"
overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="300"
memoryStoreEvictionPolicy="LRU"/>
</ehcache>
java中使用注解
@Override
@Cacheable(value="users",key="'user_'+#id")
public User getUserById(Long id) {
return userMapper.selectByPrimaryKey(id);
}
@Override
@CacheEvict(value="users",allEntries=true)
public int saveUser(User user) {
return userMapper.insertSelective(user);
}
4. durid 使用
WebServlet 配置
@WebServlet(urlPatterns = "/druid/*",
initParams={
@WebInitParam(name="allow",value=""),// IP白名单 (没有配置或者为空,则允许所有访问, 逗号分隔)
@WebInitParam(name="deny",value=""),// IP黑名单 (存在共同时,deny优先于allow)
@WebInitParam(name="loginUsername",value="admin"),// 用户名
@WebInitParam(name="loginPassword",value="admin"),// 密码
@WebInitParam(name="resetEnable",value="false")// 禁用HTML页面上的“Reset All”功能
})
public class DruidController extends StatViewServlet {
}
Filter 配置
@WebFilter(filterName="druidWebStatFilter",urlPatterns="/*",
initParams={
@WebInitParam(name="exclusions",value="*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")// 忽略资源
})
public class DruidStatFilter extends WebStatFilter {
}
三、效果图如下:
增加数据


第一次执行


第二次执行


四、程序目录结构

五、其他补充
springBoot介绍
百度百科:https://baike.baidu.com/item/Spring Boot/20249767?fr=aladdin
spring官方:https://projects.spring.io/spring-boot/
SpringBoot 框架整合
注:本文著作权归作者,由demo大师代发,拒绝转载,转载需要作者授权
SpringBoot 框架整合的更多相关文章
- dubbo+zookeeper+springBoot框架整合与dubbo泛型调用演示
dubbo + zookeeper + spring Boot框架整合与dubbo泛型调用演示 By:客 授客 QQ:1033553122 欢迎加入全国软件测试交流 QQ 群:7156436 ...
- SpringBoot 框架整合webservice
spring boot集成web service框架 题记: 本篇博客讲的spring boot如何集成 spring web service,如果您想用Apache CXF集成,那么可能不适合您.为 ...
- 快速搭建springboot框架以及整合ssm+shiro+安装Rabbitmq和Erlang、Mysql下载与配置
1.快速搭建springboot框架(在idea中): file–>new project–>Spring Initializr–>next–>然后一直下一步. 然后复制一下代 ...
- Springboot(2.0.0.RELEASE)+spark(2.1.0)框架整合到jar包成功发布(原创)!!!
一.前言 首先说明一下,这个框架的整合可能对大神来说十分容易,但是对我来说十分不易,踩了不少坑.虽然整合的时间不长,但是值得来纪念下!!!我个人开发工具比较喜欢IDEA,创建的springboot的j ...
- JavaSSM框架整合
SSM整合 ssm框架 框架整合 在博客的前面介绍了mybatis,spring,springmvc的使用,那么这篇博客将介绍将mybatis和spring,springmvc的整合. 整合之前,我 ...
- 纯手写SpringMVC到SpringBoot框架项目实战
引言 Spring Boot其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. 通过这种方式,springboot ...
- SpringBoot+SpringData 整合入门
SpringData概述 SpringData :Spring的一个子项目.用于简化数据库访问,支持NoSQL和关系数据存储.其主要目标是使用数据库的访问变得方便快捷. SpringData 项目所支 ...
- spring boot 学习(二)spring boot 框架整合 thymeleaf
spring boot 框架整合 thymeleaf spring boot 的官方文档中建议开发者使用模板引擎,避免使用 JSP.因为若一定要使用 JSP 将无法使用. 注意:本文主要参考学习了大神 ...
- springBoot 官方整合的redis 使用教程:(StringRedisTemplate 方式存储 Object类型value)
前言:最近新项目准备用 redis 简单的缓存 一些查询信息,以便第二次查询效率高一点. 项目框架:springBoot.java.maven 说明:edis存储的数据类型,key一般都是Strin ...
随机推荐
- Cocoa Pods 'No such file or Directory' Error
http://stackoverflow.com/questions/27727998/cocoa-pods-no-such-file-or-directory-error 0down votefav ...
- 6.安装和配置OpenStack图片服务组件
安装和配置图片服务组件 这里是安装在控制器上 安装和配置图片服务组件 yum install –y openstack-glance python-glanceclient 编辑/etc/glance ...
- Python学习杂记_12_函数(三)
内置函数 Python有很多内置函数,以下这些是常用且必须要掌握的: 强制类型转换: bool() # 把一个对象转换成布尔类型 int() # 整形 float() # 小数 str() # 字符 ...
- 【linux高级程序设计】(第十章)Linux异步信号处理机制 3
信号屏蔽 信号忽略:系统仍然传递该信号,只是相应的进程不做任何处理 信号屏蔽:进程不捕获信号,信号处于未决状态,当不再屏蔽信号时可以捕获之前被屏蔽的信号. 信号集数据结构定义: typedef __s ...
- 基于最新友盟开发文档,集成友盟分享功能,赋demo
集成准备 获取Appkey 快速集成 获取SDK,页面截图: 下载后打开 导入jar和res 添加回调Activity 微信 在包名目录下创建wxapi文件夹,新建一个名为WXEntryActivit ...
- R 语言词云wordcloud
来源:http://blog.chinaunix.net/uid-25135004-id-4311592.html wordcloud函数--用于绘制词云图 用法: wordcloud(words,f ...
- Codeforces Round #445 B. Vlad and Cafes【时间轴】
B. Vlad and Cafes time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Python的程序结构[3] -> 变量/Variable[1] -> LEGB 法则
LEGB法则 / LEGB Rule LEGB 变量搜索顺序 ---- 来源于<Python学习手册>/ Learning Python Page 419 ---- Python 的变量名 ...
- vue的路由设置小结
vue的路由设置小结 // 异步路由的编写示例.其中针对component字段进行懒加载及分块处理,提升首屏加载速度的同时,也可以手动控制让某些页面合并到一个单独的js文件中,而不是每个页面都是一个j ...
- Moving Average from Data Stream -- LeetCode
Given a stream of integers and a window size, calculate the moving average of all integers in the sl ...