第一步:添加二級緩存配置文件ehcache.xml到項目的src目錄
ehcache.xml文件可以在hibernate-release-4.2.4.Final\project\etc目錄下找到
第二步:配置hibernate.cfg.xml文件
1、首先添加二級緩存支持:
<property name="cache.use_second_level_cache">true</property>
2、添加二級緩存服務提供類:
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
3、添加需要用到二級緩存的類
<class-cache usage="read-only" class="com.study.bean.Student"/>
第三步:添加commons-logging-1.1.3.jar,不然會報錯下載地址:http://apache.dataguru.cn//commons/logging/binaries/commons-logging-1.1.3-bin.zip