Java hibernate ehcache配置问题:从null配置时出错。最初的原因是无效的

Java hibernate ehcache配置问题:从null配置时出错。最初的原因是无效的,java,hibernate,ehcache,Java,Hibernate,Ehcache,我试图在hibernate版本3的产品中实现二级缓存 但是,当我尝试访问我的应用程序时,出现以下错误: [HibernateSessionFactory]: 位于的java.lang.NullPointerException net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:102) [wrapped]net.sf.ehcache.CacheException:从null

我试图在hibernate版本3的产品中实现二级缓存

但是,当我尝试访问我的应用程序时,出现以下错误:

[HibernateSessionFactory]:

位于的java.lang.NullPointerException net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:102) [wrapped]net.sf.ehcache.CacheException:从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)

[wrapped]org.hibernate.cache.CacheException: net.sf.ehcache.CacheException:从null配置时出错。首字母 原因是无效的

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

在 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
线
真的
真的
真的
真的
org.hibernate.cache.EhCacheProvider
net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
...
...
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

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

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

连续尝试3天后,我发现了问题。根据互联网上的帖子,我发现它只从类路径读取配置

虽然我的两个配置文件位于同一位置,但它们位于classpath:config/位置。因此,按照以下步骤更改配置对我来说很有效:

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

对我来说,它通过替换以下行来工作:

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

META-INF/config/ehcache.xml

虽然两个文件位于同一文件夹中,但它无法识别该文件。因此,META-INF成功了。

我也尝试了这个选项,但没有成功。然而,经过3天的时间浪费,我找到了解决办法。请检查我的答案是否相同。是的。。。如果您的文件在config/中,那么指定它似乎是一种方法。。。你应该告诉我们你的问题中的文件在哪里。它看起来像是在类路径的根上。
<property name="net.sf.ehcache.configurationResourceName">META-INF/config/ehcache.xml</property>