Hibernate 5.3 Spring 5,Ehcache 3.5.2,jdk 10,Hibernate 说“缓存提供程序未启动”

问题描述 投票:0回答:3

...我的问题是,使用此配置,我是否需要“启动”ehcache?如果是,怎么办?这是一个通过库依赖项工作的迷宫,例如需要 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
3个回答
0
投票

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

我能说的第一件事是

hibernate-ehcache
不应该在那里。这是用于 Ehcache 2 的。不是 JCache+Ehcache3。

那么,您可以尝试将

jcache.xml
重命名为
ehcache.xml
吗?

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


0
投票

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 配置就不会被读取。我已经使用 Spring 2.5 13 年了,所以我还没有理解 Spring Boot 是什么。它被认为是“Spring 平台和第三方库的固执己见的视图,因此您可以以最小的麻烦开始使用”。但它似乎也是一个运行时/嵌入式 tomcat,所以无论如何,我确信它有时非常有用,并且非常未定义并且使其他人感到困惑......


0
投票

我也有同样的问题。仅检查此消息:缓存提供程序未启动并没有真正帮助我。我必须抛出整个异常才能获得更多详细信息。 就我而言,在抛出整个异常堆栈后,我遇到了几个错误:

  • 有时提供商无法找到我的 ehcache.xml 文件
  • 有时提供程序无法解析我的 ehcache.xml 文件内容

这是我的设置:

Pom.xml

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>6.0.0.Alpha7</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-jcache</artifactId>
        <version>6.4.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>3.10.8</version>
        <classifier>jakarta</classifier>
    </dependency>

hibernate.cfg.xml

    <property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">jcache</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.javax.cache.provider">org.ehcache.jsr107.EhcacheCachingProvider</property>
<property name="hibernate.javax.cache.uri">ehcache.xml</property>

ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>

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

<cache alias="default-query-results-region">
    <expiry><ttl unit="minutes">60</ttl></expiry>
    <heap unit="entries">1000</heap>
</cache>

<cache alias="default-update-timestamps-region">
    <expiry><none/></expiry>
    <heap unit="entries">1000</heap>
</cache>

<cache-template name="default">
    <expiry>
        <!-- We can not use tti and ttl at the same time -->
        <!-- TimeToIdle : the object will be invalidated if it hasn't been requested for x seconds-->
        <!-- TimeToLive : the object will be removed from cache after x seconds, even if it has been requested few milliseconds in the xth second of its short life-->
        <tti unit="seconds">120</tti>
    </expiry>
    <heap>1024</heap>
</cache-template>

<cache alias="supportedCurrency">
    <key-type>java.lang.Long</key-type>
    <value-type>com.coder.hms.entities.SupportedCurrency</value-type>
    <expiry>
        <!-- TimeToLive : the object will be removed from cache after 120 seconds, even if it has been requested few milliseconds in the 120th second of its short life-->
        <ttl>120</ttl>
    </expiry>
    <heap unit="entries">10000</heap>
</cache>
© www.soinside.com 2019 - 2024. All rights reserved.