1.下载相关的包,下载hibernate-release-4.2.2.Final,解压后将ehcache-core-2.4.3.jar、hibernate-ehcache-4.2.2.Final.jar、slf4j-api-1.6.1.jar引入到项目工程中,该jar文件
在路径hibernate-release-4.2.2.Final\lib\optional\ehcache下。
2.hibernate-release-4.2.2.Final\project\hibernate-ehcache\src\test\resources下的ehcache.xml放到src路径下
3.配置相关参数
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQL5Dialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<!-- 配置二级缓存提供商 -->
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
<!-- 加载缓存所需配置文件 -->
<prop key="hibernate.net.sf.ehcache.configurationResourceName">classpath:ehcache.xml</prop>
</props>
</property>
</bean>