【发布时间】:2018-04-09 21:07:02
【问题描述】:
我正在尝试使用休眠版本 3 在我们的产品中实现二级缓存。
但是,当我尝试访问我的应用程序时,出现以下错误:
[休眠会话工厂]:
java.lang.NullPointerException 在 net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:102) [已包装] net.sf.ehcache.CacheException:从 null 配置时出错。 最初的原因是 null
在 net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:105)
在 net.sf.ehcache.hibernate.HibernateUtil.loadAndCorrectConfiguration(HibernateUtil.java:51)
在 net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory.start(SingletonEhCacheRegionFactory.java:76)
[包装] org.hibernate.cache.CacheException: net.sf.ehcache.CacheException:从 null 配置时出错。最初的 原因为空
在 net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory.start(SingletonEhCacheRegionFactory.java:82)
在 org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:238)
在 org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
hibernate.cfg.xml:
<hibernate-configuration>
<session-factory>
<property name="net.sf.ehcache.configurationResourceName">ehcache.xml</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_structured_entries">true</property>
<property name="hibernate.cache.generate_statistics">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory</property>
...
...
</session-factory>
</hibernate-configuration>
ehcache.xml
<ehcache>
<defaultCache maxElementsInMemory="100" eternal="false"
timeToIdleSeconds="500" timeToLiveSeconds="1000" />
<cache name="Audit" maxElementsInMemory="100"
eternal="false" timeToIdleSeconds="500" timeToLiveSeconds="1000" />
</ehcache>
我正在使用以下 jar 来实现缓存:
- ehcache-core-2.6.10.jar
- hibernate-3.6.6.jar
- hibernate-validator-4.2.0.Final.jar
请指导我,哪里出错了。为什么它将文件显示为空。两个配置文件都在同一个文件夹中。
【问题讨论】: