如果在/sandh/web-inf/classes下面沒有ehcache.xml這個文件,會報這個錯誤,No configuration found.
Configuring ehcache from ehcache-failsafe.xml found in the classpath:.....這個文件是hibernate緩存配置文
件
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="10000"
timeToLiveSeconds="10000"
overflowToDisk="true"
/>
<cache name="com.hour41.hibernate.vo.common.City"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="10000"
timeToLiveSeconds="10000"
overflowToDisk="true"
/>
</ehcache>
上面配置了默認類緩存和城市類緩存策略:
<diskStore>表示當內存緩存中對象數量超過類設置內存緩存數量時,將緩存對象寫到硬盤,path=”java.io.tmpdir
”表示把數據寫到這個目錄下。Java.io.tmpdir目錄在運行時會根據相對路徑生成。
<defaultCache>表示設定緩存的默認數據過期策略。
<cache>表示設定用具體的命名緩存的數據過期策略。
name表示具體的緩存命名。
maxElementsInMemory表示cache中最大允許保存的對象數據量。
eternal表示cache中數據是否為常量。
timeToIdleSeconds表示緩存數據鈍化時間
timeToLiveSeconds表示緩存數據的生命時間。
overflowToDisk表示內存不足時,是否啟用磁盤緩存。
將上面代碼另存為ehcache.xml存放在lib/classes里面即可!