2017-10-28 222 views
0

我想实现我们的产品二级缓存与Hibernate版本3hibernate ehcache配置问题:从null配置错误。最初的原因是空

然而,当我尝试访问我的申请,我得到以下错误:

[ HibernateSessionFactory ] :

java.lang.NullPointerException at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:102) [wrapped] net.sf.ehcache.CacheException: Error configuring from null. Initial cause was null

at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:105)

at net.sf.ehcache.hibernate.HibernateUtil.loadAndCorrectConfiguration(HibernateUtil.java:51)

at net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory.start(SingletonEhCacheRegionFactory.java:76)

[wrapped] org.hibernate.cache.CacheException: net.sf.ehcache.CacheException: Error configuring from null. Initial cause was null

at net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory.start(SingletonEhCacheRegionFactory.java:82)

at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:238)

at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)

休眠。 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> 

我使用下面的罐来实现缓存:

  • ehcache的核心 - 2.6.10.jar
  • 休眠-3.6.6.jar
  • 休眠 - 验证 - 4.2.0。 Final.jar

请指导我,哪里出问题了。为什么它显示文件为空。两个配置文件都在同一个文件夹中。

回答

0

它似乎是找不到的ehcache,xml文件。你能用/ehcache.xml来尝试吗?

+0

我也试过这个选项,但它没有奏效。然而,经过3天的浪费,我找到了解决方案。请检查我的答案是否一样。 –

+0

是的......如果你的文件在配置/然后指定它似乎要走的路......你应该告诉我们该文件在你的问题的位置。它看起来像是在类路径的根部。 – Henri

0

经过3天的连续尝试,我发现了这个问题。根据互联网上的帖子,我发现它只从classpath读取配置。

尽管我的两个配置文件位于相同的位置,但它们位于classpath:config/的位置。所以改变我的配置,因为以下工作对我来说:

<property name="net.sf.ehcache.configurationResourceName">config/ehcache.xml</property>