mybatis结合ehcache开启二级缓存时需要配置的一些东西。
1、导入mybtais-ehcache.jar包和ehcache-core.jar核心包
2、在mybatis-config.xml中加入settings
<!-- 开启二级缓存-->
<settings>
<setting name="cacheEnabled" value="true"/>
</settings>
3、在相应的mapper.xml文件中加入cache
<cache type="org.mybatis.caches.ehcache.EhcacheCache"></cache>
4、新建一个ehcahce.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
<diskStore path="E:/rzpbatis/ehcache"/> 这是自己创建的一个路径
<defaultCache
maxElementsInMemory="10000"
maxElementsOnDisk="10000000"
eternal="false"
overflowToDisk="false"
diskPersistent="true"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
</defaultCache>
</ehcache>
5、在实体类中加入序列化:Serializable
public class Teacher implements Serializable