5

I want EhCache to create caches using the default template. Here's my ehcache.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<config
    xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns='http://www.ehcache.org/v3'
    xsi:schemaLocation="
        http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
        http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
  <service>
    <jsr107:defaults default-template="default" jsr-107-compliant-atomics="true">
    </jsr107:defaults>
  </service>

  <cache-template name="default">
    <expiry>
      <ttl unit="seconds">5</ttl>
    </expiry>
    <heap>100</heap>
  </cache-template>
<!--  <cache alias="test" uses-template="default" />--> <!-- I want to omit this. -->
</config>

Here's my application.yml file:

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

I don't want to have to update ehcache.xml every time I add need new cache name. How do I configure EhCache with Spring Boot to use my default Template?

If I don't specify the cache name configuration, I get this error:

java.lang.IllegalArgumentException: Cannot find cache named 'test' for CacheResultOperation
George
  • 2,820
  • 4
  • 29
  • 56

1 Answers1

0

I believe you are missing this configuration:

properties.put("hibernate.javax.cache.missing_cache_strategy", "create-warn"); //Use create if you don't want to see a warning
jumping_monkey
  • 5,941
  • 2
  • 43
  • 58