通过hibernate.cache.provider_configuration_file_resource_path属性配置
方式一,修改hibernate.cfg.xml文件:
<!-- 开启二级缓存,使用EhCache缓存 -->
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<!-- 配置EhCache的配置文件的路径,默认是ehcache.xml -->
<property name="hibernate.cache.provider_configuration_file_resource_path">ehcacheCfg/ehcache.xml</property>
方式二,如果集成了spring框架,就修改applicationContext.xml文件:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
......
<property name="hibernateProperties">
<props>
......
<!-- 开启二级缓存,使用EhCache缓存 -->
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<!-- 配置EhCache的配置文件的路径,默认是ehcache.xml -->
<prop key="hibernate.cache.provider_configuration_file_resource_path">ehcacheCfg/ehcache.xml</prop>
......
</props>
</property>
<property name="mappingResources">
<list>
<value>edu/po/Users.hbm.xml</value>
<value>edu/po/TLog.hbm.xml</value>
</list>
</property>
</bean>