【问题标题】:Hibernate 5.3 Spring 5, Ehcache 3.5.2, jdk 10, Hibernate says "Cache provider not started"Hibernate 5.3 Spring 5,Ehcache 3.5.2,jdk 10,Hibernate 说“缓存提供程序未启动”
【发布时间】:2018-05-24 20:43:37
【问题描述】:

...我的问题是,使用这种配置,我是否需要“启动”ehcache?如果是,如何?这是一个通过 libs 依赖项工作的迷宫,例如需要hibernate-ehcache和ehcache?需要hibernate-jcache?这是 3 天调试后 tomcat 9 标准输出的最终错误:

       ... 93 common frames omitted
aused by: java.lang.IllegalStateException: Cache provider not started
       at org.hibernate.cache.spi.AbstractRegionFactory.verifyStarted(AbstractRegionFactory.java:42)
       at org.hibernate.cache.spi.support.RegionFactoryTemplate.buildTimestampsRegion(RegionFactoryTemplate.java:66)
       at org.hibernate.cache.internal.EnabledCaching.<init>(EnabledCaching.java:80)
       at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:33)
       at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:24)
       at org.hibernate.service.spi.SessionFactoryServiceInitiator.initiateService(SessionFactoryServiceInitiator.java:
0)
       at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistr
Impl.java:68)
       at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263

关键配置文件:

ivy.xml(摘录):

<dependency org="org.hibernate" name="hibernate-core" rev="5.3.0.Final">
</dependency>

<dependency org="org.hibernate" name="hibernate-jcache" rev="5.3.0.Final" />

<dependency org="org.hibernate" name="hibernate-ehcache"
    rev="5.3.0.Final" />


<dependency org="org.springframework.boot" name="spring-boot-starter-cache"
    rev="2.0.2.RELEASE" />


<dependency org="org.ehcache" name="ehcache" rev="3.5.2" />

<dependency org="org.springframework" name="spring-orm" rev="5.0.6.RELEASE" />
<dependency org="org.springframework" name="spring-core"
    rev="5.0.6.RELEASE" />

Spring hibernateContext.xml(摘录)

<property name="hibernateProperties">
        <props>
            <prop key="hibernate.c3p0.acquire_increment">5</prop>
            <prop key="hibernate.c3p0.idle_test_period">100</prop>
            <prop key="hibernate.c3p0.max_size">20</prop>
            <prop key="hibernate.c3p0.max_statements">50</prop>
            <prop key="hibernate.c3p0.min_size">5</prop>
            <prop key="hibernate.c3p0.timeout">300</prop>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.format_sql">false</prop>
            <prop key="hibernate.use_sql_comments">false</prop>

            <!-- <prop key="hibernate.enable_lazy_load_no_trans">true</prop> -->

            <!-- ehcache settings -->

            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.jcache.JCacheRegionFactory</prop>
            <prop key="hibernate.javax.cache.provider">org.ehcache.jsr107.EhcacheCachingProvider</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.cache.default_cache_concurrency_strategy">read-write</prop>
            <prop key="hibernate.javax.cache.uri">classpath:jcache.xml</prop>

        </props>
    </property>

</bean>

jcache.xml(全部)

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.ehcache.org/v3" xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="
        http://www.ehcache.org/v3
        http://www.ehcache.org/schema/ehcache-core.xsd
        http://www.ehcache.org/v3/jsr107
        http://www.ehcache.org/schema/ehcache-107-ext.xsd">

<!-- https://hibernate.atlassian.net/browse/HHH-12531 -->
<service>
    <jsr107:defaults enable-management="true" enable-statistics="true" default-template="default" />
</service>

<cache alias="org.hibernate.cache.spi.QueryResultsRegion">
    <expiry>
        <tti unit="seconds">300</tti>
    </expiry>
    <heap>1024</heap>
</cache>

<cache alias="org.hibernate.cache.spi.TimestampsRegion">
    <expiry>
        <none />
    </expiry>
    <heap>4096</heap>
</cache>

<cache-template name="default">
    <expiry>
        <tti unit="seconds">300</tti>
    </expiry>
    <heap>1024</heap>
</cache-template>

也造成了休眠问题 https://hibernate.atlassian.net/browse/HHH-12635

【问题讨论】:

    标签: spring hibernate ehcache


    【解决方案1】:

    我不确定在 Hibernate 中创建问题是否是个好主意。这很可能是您这边的配置问题。

    我可以说的第一件事是hibernate-ehcache 不应该在那里。这用于 Ehcache 2。不是 JCache+Ehcache3。

    那么,您能否尝试将jcache.xml 重命名为ehcache.xml

    最后,不,您应该不需要启动所提供的。它应该自行启动。

    【讨论】:

    • 嗨,Henri,感谢您处理这个问题。 ...我逐步尝试了您的想法,并且在每次更改时,错误、堆栈跟踪和错误消息都保持不变。 hibernate 的 org.hibernate.cache.spi.AbstractRegionFactory 的调试时间。任何想法如何用tomcat9启动的eclipse进行步进调试?如果没有,我将继续记录日志,这意味着,重建休眠,重新部署到 ivy 本地,构建,部署,重新启动循环......
    • 这取决于你如何启动tomcat。但在全局范围内,只需使用suspend=y 将远程调试参数添加到JVM。然后附上Eclipse就可以调试了。
    • 但那是在tomcat运行之后(AJP)?我的错误发生在我的 web 应用程序尝试部署/spring init 时......所以除非我听到其他更好的想法,否则我将跳入 hobernate 5.3 核心代码,让 hibernate gradle 构建工作,然后尝试找出问题所在....
    • ...或mabe将eclipse ajp调试器附加到tomcat,然后重新部署...将首先尝试,看看我是否可以在hibernate 5.3核心org.hibernate.cache中获得断点。 spi.AbstractRegionFactory
    • eclipse 在调试和重新部署工作,问题是:javax.cache.CacheException: org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at classpath:jcache.xml
    【解决方案2】:

    Henri 说得对,我不需要 hibernate-ehcache。但是不需要将 jcache.xml 重命名为 ehcache.xml。

    简而言之,我的错误的修复是将 jcache.xml 资源添加到我的 ant 构建中,因为它没有被部署。话虽如此,对于可能有此错误的其他人来说,对于 hibernate 5.3、spring 5、ehcache 3.5.2、jdk 10、tomcat 9,您唯一的希望(其他比愚蠢的运气,这确实有效)是将tomcat置于调试模式,附加eclipse,将hibernate-core源添加到eclipse项目中,在有问题的hibernate类/方法中设置一个断点,看看你的特殊配置。

    对于其他试图完成这项工作的人来说,奇怪的是,我确实需要 spring-boot-starter-cache,没有它,我的 spring hibernate 配置都不会被读取。我是 13 年的 Spring 2.5 人,所以我还没有理解什么是弹簧靴。它应该是“对 Spring 平台和第三方库的看法,因此您可以以最小的麻烦开始”。但它似乎也是一个运行时/嵌入式 tomcat,所以无论如何,我相信它有时非常有用,而且非常未定义和混淆其他人......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多