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

j2cgzkjk  于 12个月前  发布在  Spring
关注(0)|答案(3)|浏览(114)

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

... 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

5anewei6

5anewei61#

我不确定在Hibernate中创建一个问题是不是一个好主意。这很可能是你这边的一个配置问题。
我能说的第一件事是hibernate-ehcache不应该在那里。这是用于Ehcache 2的。而不是JCache+ Ehcache 3。
那么,您可以尝试将jcache.xml重命名为ehcache.xml吗?
最后,不,你不需要启动提供的。它应该自己启动。

a14dhokn

a14dhokn2#

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家伙,所以我还没有理解Sping Boot 是什么。它被认为是“Spring平台和第三方库的一个固执己见的观点,这样你就可以开始最小的麻烦”.但它似乎也是一个运行时/嵌入式tomcat,所以无论如何,我相信它有时是非常有用的,而且还没有定义,让其他人感到困惑。

jgovgodb

jgovgodb3#

我也遇到了同样的问题。只检查这个消息:Cache provider not started并没有真正帮助我。我必须抛出整个异常以获得更多细节。在我的情况下,在抛出整个异常堆栈后,我有几个错误:

  • 有时提供程序无法找到我的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>

相关问题