spring boot 集成EHCache

本章知识点:Spring Data JPA,Spring Boot 使用Mysql,Spring MVC,EHCache,Spring Cache等(其中@Cacheable请看上一节的理论知识),具体分如下几个步骤:

步骤 描述
1 新建Maven Java Project
2 在pom.xml中加入依赖包
3 编写Spring Boot启动类;
4 配置application.properties;
5 编写缓存配置类以及ehcache.xml配置文件
6 编写DemoInfo实体类进行测试;
7 编写持久类DemoInfoRepository;
8 编写处理类DemoInfoService;
9 编写DemoInfoController测试类;运行测试

接下来是具体实现

1)新建Maven Java Project

 新建一个工程名为spring-boot-ehcache的maven java project。

(2)在pom.xml中加入依赖包

  在pom.xml文件中加入相应的依赖包,Spring Boot父节点依赖包;spring boot web支持;缓存依赖spring-context-support;集成ehcache需要的依赖;JPA操作数据库;mysql 数据库驱动,具体pom.xml文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
< 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.kfit</ groupId >
     < artifactId >spring-boot-ehcache</ artifactId >
     < version >0.0.1-SNAPSHOT</ version >
     < packaging >jar</ packaging >
  
     < name >spring-boot-ehcache</ name >
     < url >http://maven.apache.org</ url >
  
     < properties >
        < project.build.sourceEncoding >UTF-8</ project.build.sourceEncoding >
  
        <!-- 配置JDK编译版本. -->
        < java.version >1.8</ java.version >
     </ properties >
  
  
     <!-- spring boot 父节点依赖,
        引入这个之后相关的引入就不需要添加version配置,
         spring boot会自动选择最合适的版本进行添加。
     -->
     < parent >
        < groupId >org.springframework.boot</ groupId >
        < artifactId >spring-boot-starter-parent</ artifactId >
        < version >1.3.3.RELEASE</ version >
     </ parent >
  
     < dependencies >
        <!-- 单元测试. -->
        < dependency >
            < groupId >junit</ groupId >
            < artifactId >junit</ artifactId >
            < scope >test</ scope >
        </ dependency >
  
        <!-- spring boot web支持:mvc,aop... -->
        < dependency >
            < groupId >org.springframework.boot</ groupId >
            < artifactId >spring-boot-starter-web</ artifactId >
        </ dependency >
       
        <!--
            包含支持UI模版(Velocity,FreeMarker,JasperReports),
            邮件服务,
            脚本服务(JRuby),
            缓存Cache(EHCache),
            任务计划Scheduling(uartz)。
         -->
        < dependency >
           < groupId >org.springframework</ groupId >
           < artifactId >spring-context-support</ artifactId >
         </ dependency >
  
        <!-- 集成ehcache需要的依赖-->
        < dependency >
            < groupId >net.sf.ehcache</ groupId >
            < artifactId >ehcache</ artifactId >
        </ dependency >
       
        <!-- JPA操作数据库. -->
        < dependency >
           < groupId >org.springframework.boot</ groupId >
           < artifactId >spring-boot-starter-data-jpa</ artifactId >
         </ dependency >
       
        <!-- mysql 数据库驱动. -->
        < dependency >
          
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值