我正在尝试将 Ehcache (2.6.0) 配置为 Hibernate (3.6.4) 二级缓存。我在 spring 上下文文件中设置了以下属性
<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">net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory</prop>
当我启动应用程序时,它失败并出现以下异常:java.lang.ClassCastException: net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory cannot be cast to org.hibernate.cache.RegionFactory
这是堆栈跟踪:
Caused by: org.hibernate.HibernateException: could not instantiate RegionFactory [net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory]
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:423)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:280)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
Caused by: java.lang.ClassCastException: net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory cannot be cast to org.hibernate.cache.RegionFactory
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:409)
我查看了源代码并观察到了这 SingletonEhCacheRegionFactory extends AbstractEhcacheRegionFactory
一点AbstractEhcacheRegionFactory implements RegionFactory
SettingsFactory.java:409 的代码是
return (RegionFactory) ReflectHelper.classForName( regionFactoryClassName )
.getConstructor( Properties.class )
.newInstance( properties );
一切似乎都到位,但我仍然得到例外。有什么线索吗?