第一步spring-hibernate.xml文件增加属性
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
</props>
</property>
第二部 src目录下创建 缓存文件 ehcache.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<ehcachexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<diskStorepath="java.io.tmpdir/EhCacheSpringAnnotationsExampleApp"/>
<defaultCacheeternal="false"maxElementsInMemory="1000"
overflowToDisk="false"diskPersistent="false"timeToIdleSeconds="0"
timeToLiveSeconds="600"memoryStoreEvictionPolicy="LRU"/>
</ehcache>
<!-- <cachename="org.hibernate.cache.StandardQueryCache"-->
<!-- maxElementsInMemory="10000"-->
<!-- eternal="false"-->
<!-- timeToIdleSeconds="300"-->
<!-- timeToLiveSeconds="4200"-->
<!-- overflowToDisk="true"-->
<!-- />-->
<!---->
<!-- Sample cache named sampleCache2-->
<!-- This cache contains 1000 elements.Elements will always be held in memory.-->
<!-- They are not expired. -->
<!---->
<!-- <cachename="org.hibernate.cache.UpdateTimestampsCache"-->
<!-- maxElementsInMemory="5000"-->
<!-- eternal="true"-->
<!-- timeToIdleSeconds="0"-->
<!-- timeToLiveSeconds="0"-->
<!-- overflowToDisk="false"-->
<!-- /> -->
<!---->
<!-- <cachename="com.csst.club.domain.code.TCodeCertiType"-->
<!-- maxElementsInMemory="5000"-->
<!-- eternal="true"-->
<!-- timeToIdleSeconds="120"-->
<!-- timeToLiveSeconds="120"-->
<!-- overflowToDisk="false"-->
<!-- /> -->
<!---->
第三部映射文件加入配置项 <cache></cache>
使用缓存查找集合