return sb.toString();
}
};
}

3在resources目次下添加ehcache.xml设置装备摆设文件 , spring boot会默认读取类根路径下ehcache.xml设置装备摆设文件 , 添加了一个名为users的缓存空间,代码如下
<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>

4添加一个User实体类 , 用于缓存测试 , 代码如下
public class User implements Serializable {
private String id;
private String name;
public User(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
【spring boot整合ehcache缓存框架】 this.name = name;
}
@Override
public String toString() {
猜你喜欢
- bootmgr is missing怎么解决?
- spring boot配置mongo,并保存数据
- spring boot配置redis
- 如何用手机把多段TS格式文件合并整合成一个MP4
- 如何学习spring的源码之spring的整体架构介绍
- 开机显示reboot and select proper boot device
- 如何学习spring源码之spring生态介绍
- spring security的logout功能404怎么办
- spring security自定义filter
- Creo6.0软件怎么安装
