how to use ehcache in spring mvc with hibernate

流过昼夜 提交于 2019-12-23 04:06:14

问题


I am new to spring-mvc and want to integrate ehcache as second level cache in hibernate. I followed this tutorial ehcache Now entries in my hibernate.xml are as follows:

<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</property>
<property name="hibernate.generate_statistics">true</property>

entries in ehcache.xml are as follows:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">

<diskStore path="java.io.tmpdir"/>
<!--defaultCache
        eternal="false"
        maxElementsInMemory="1000"
        maxElementsOnDisk="10000"
        overflowToDisk="true"
        diskPersistent="true"
        timeToLiveSeconds="300"
        statistics="true"
        copyOnWrite="true"
/-->

<cache name="com.payupaisa.cms.model.Event" 
 maxElementsInMemory="100000" 
 eternal="true" 
 overflowToDisk="false"
 memoryStoreEvictionPolicy="LFU"
 statistics="true"
timeToLiveSeconds="3600"
/>

</ehcache>

we are following mvc model and in model i defined annootation

@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY,
region="department")

Now issue is how to start using this cache in service layer. I have not created hibernateUtil.java in my project. we are having web based spring-hibernate mvc application. Now how to start , i am not getting.


回答1:


This example shows you an example to integrate Spring + Hibernate + EHCache.



来源:https://stackoverflow.com/questions/21827993/how-to-use-ehcache-in-spring-mvc-with-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!