boot/ehcache不使用指定的配置文件?

ohfgkhjo  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(155)

我正在尝试在springboot2应用程序中启用ehcache 3缓存,并且尽我所知我已经正确地设置了它,但是缓存只是…不起作用,我没有得到任何关于原因的信息。
我在maven pom中添加了:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
    <groupId>org.ehcache</groupId>
    <artifactId>ehcache</artifactId>
</dependency>
<dependency>
    <groupId>javax.cache</groupId>
    <artifactId>cache-api</artifactId>
</dependency>

我添加了一个 @EnableCaching 注解。我已经指定了配置,我正在使用 bootstrap.yml 所以:

spring:
  cache:
    jcache:
      config: classpath:ehcache.xml

但以防万一我也把 spring.cache.jcache.config 属性文件中的版本。
我写了一个基本的 src/main/resources/ehcache.xml 文件。。。
最后,我将一个方法设置为 @Cacheable 但当我用“找不到名为…”的缓存调用它时,它会出错
我写什么一点都不重要 ehcache.xml . 我可以粘贴在lorem ipsum文本,而不是xml,没有错误或迹象表明它甚至打开了文件。
spring boot本身似乎找到了jsr 107自动配置的适当先决条件:

JCacheCacheConfiguration matched:
      - @ConditionalOnClass found required classes 'javax.cache.Caching', 'org.springframework.cache.jcache.JCacheCacheManager' (OnClassCondition)
      - Cache org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration automatic cache type (CacheCondition)

我试着回到ehcache 2,所以我换了 org.ehcachenet.sf.ehcache ,将我的yml改为 ehcache 而不是 jcache 并被移除 javax.cache . 这会将其放入我的自动配置报告中:

EhCacheCacheConfiguration matched:
      - @ConditionalOnClass found required classes 'net.sf.ehcache.Cache', 'org.springframework.cache.ehcache.EhCacheCacheManager' (OnClassCondition)
      - Cache org.springframework.boot.autoconfigure.cache.EhCacheCacheConfiguration automatic cache type (CacheCondition)
      - ResourceCondition (EhCache) found resource 'classpath:/ehcache.xml' (EhCacheCacheConfiguration.ConfigAvailableCondition)

但我仍然没有任何可用的缓存。为什么spring的自动配置机制会提到它找到了ehcache 2配置文件,但实际上没有配置任何东西?我是否还需要在报表中查找其他自动配置类,如genericcache、cacheconfiguration或其他类?
我看不到任何迹象表明它试图做任何事情来启动缓存子系统,读取我的配置,做任何事情。
虽然自动配置很方便,但当它不想做这件事时,它会令人沮丧地告诉我,它完全没有告诉我为什么决定要解雇我,所以我真的需要一些帮助来弄清楚如何从事情中挑出这些细节。
我错过什么了吗?我可以调试什么?我可以在哪里找到它为什么忽略我要告诉它的xml配置?我尝试在jcache设置周围向spring cacheproperties添加一些断点,但在附加调试器时没有命中。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题