博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring中配置二级缓存
阅读量:4069 次
发布时间:2019-05-25

本文共 2200 字,大约阅读时间需要 7 分钟。

<div class="postbody">
<p>1.首先,在spring的hibernate配置里(我的是applicationContext-hibernate.xml)加上如下属性:</p>
<p><bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <br><property name="dataSource"><br><ref bean="dataSource"/><br></property><br><property name="mappingResources"><br><list><br><value>org/appfteaching/model/TArticleclass.hbm.xml</value><br></list><br></property><br><property name="hibernateProperties"><br><props><br><prop key="hibernate.dialect">${hibernate.dialect}</prop><br> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop><br> <prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop><br> <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop><br><span style="color: #ff0000;"><prop key="hibernate.cache.use_query_cache">true</prop><br> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop><br></span></props><br></property><br></bean></p>
<p>2.其次,在src目录下的ehcache.xml中配置如下信息(如果是默认ehcache.xml则会有<cache name="sampleCache1">和<cache name="sampleCache2>",去掉)</p>
<p><cache name="org.hibernate.cache.StandardQueryCache"<br> maxElementsInMemory="10000"<br> eternal="false"<br> timeToIdleSeconds="300"<br> timeToLiveSeconds="4200"<br> overflowToDisk="true"<br> /></p>
<p> <!-- Sample cache named sampleCache2<br> This cache contains 1000 elements. Elements will always be held in memory.<br> They are not expired. --></p>
<p> <cache name="org.hibernate.cache.UpdateTimestampsCache"<br> maxElementsInMemory="5000"<br> eternal="true"<br> timeToIdleSeconds="0"<br> timeToLiveSeconds="0"<br> overflowToDisk="false"<br> /> </p>
<p>3.将你要缓存的model加进ehcache.xml里</p>
<p><cache name="org.appfteaching.model.TArticleclass" <br> maxElementsInMemory="1000"<br> eternal="false"<br> timeToIdleSeconds="100"<br> timeToLiveSeconds="4200"<br> overflowToDisk="true"<br> /> </p>
<p>4.最后一步,在TArticleclass.hbm.xml里加上</p>
<p><cache usage="read-write"/></p>
<p>启动Tomcat,如发现如下错误</p>
<p>Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.<br>Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.</p>
<p>则是第二步没有做,加上即可.配置完毕</p>
</div>

转载地址:http://tdaji.baihongyu.com/

你可能感兴趣的文章
project web architecture
查看>>
OS + Unix HP-UX
查看>>
OS + Unix Solaris / openSolaris
查看>>
db sql montior
查看>>
Unix + SCO UnixWare
查看>>
db db2 books
查看>>
read humor_campus
查看>>
my read_soft
查看>>
my pdfs
查看>>
framework Schedule Quartz
查看>>
IBM WebSphere Commerce Analyzer
查看>>
Unix + OS IBM Aix System Director
查看>>
Unix + OS IBM Aix FTP / wu-ftp / proftp
查看>>
framework apache commons
查看>>
my read work
查看>>
blancerServer IBM WebSphere Edge Server 6.1
查看>>
db db2 base / instance database tablespace container
查看>>
my read _job
查看>>
hd disk / disk raid / disk io / iops / iostat / iowait / iotop / iometer
查看>>
project ASP.NET
查看>>