Reputation: 359
I have problem with loading EHCache config from file ehcache.xml. During start of my SpringBoot 3 application I got a message:
Missing cache[dictionary] was created on-the-fly. The created cache will use a provider-specific default configuration: make sure you defined one. You can disable this warning by setting 'hibernate.javax.cache.missing_cache_strategy' to 'create'.
It seems that config from file ehcache.xml isn't loading, the same result is when I remove this file. File ehcache.xml is in /src/main/resources/.
I add in application properties:
logging.level.net.sf.ehcache=DEBUG
My debug.log:
27-02-2025 13:00:33.796 [main] DEBUG org.ehcache.core.spi.ServiceLocator.startAllServices - Starting 18 Services...
27-02-2025 13:00:33.800 [main] DEBUG org.ehcache.core.spi.ServiceLocator.startAllServices - All Services successfully started, 18 Services in 4ms
27-02-2025 13:00:33.800 [main] DEBUG org.ehcache.core.StatusTransitioner.succeeded - Initialize successful.
27-02-2025 13:00:33.898 [main] DEBUG o.ehcache.jsr107.ConfigurationMerger.handleStoreByValue - Using default Copier for JSR-107 store-by-value cache dictionary
27-02-2025 13:00:33.900 [main] DEBUG org.ehcache.core.EhcacheManager.createCache - Creating Cache 'dictionary' in EhcacheManager.
27-02-2025 13:00:33.901 [main] DEBUG o.e.i.i.s.s.DefaultSerializationProvider.constructSerializer - Serializer for <java.lang.Object> : org.ehcache.impl.serialization.PlainJavaSerializer@52d68eb9
27-02-2025 13:00:33.901 [main] DEBUG o.e.i.i.s.s.DefaultSerializationProvider.constructSerializer - Serializer for <java.lang.Object> : org.ehcache.impl.serialization.PlainJavaSerializer@5cbf9aee
27-02-2025 13:00:33.904 [main] DEBUG o.e.i.i.spi.copy.DefaultCopyProvider.createCopier - Copier for <java.lang.Object> : org.ehcache.impl.copy.SerializingCopier@11eb8842
27-02-2025 13:00:33.905 [main] DEBUG o.e.i.i.spi.copy.DefaultCopyProvider.createCopier - Copier for <java.lang.Object> : org.ehcache.impl.copy.SerializingCopier@4ed7db72
27-02-2025 13:00:33.943 [main] DEBUG org.ehcache.core.StatusTransitioner.debug - {cache-alias=dictionary}Initialize successful.
27-02-2025 13:00:33.955 [main] DEBUG o.ehcache.jsr107.ConfigurationMerger.handleStoreByValue - Using default Copier for JSR-107 store-by-value cache hotel
27-02-2025 13:00:33.955 [main] DEBUG org.ehcache.core.EhcacheManager.createCache - Creating Cache 'hotel' in EhcacheManager.
27-02-2025 13:00:33.955 [main] DEBUG o.e.i.i.s.s.DefaultSerializationProvider.constructSerializer - Serializer for <java.lang.Object> : org.ehcache.impl.serialization.PlainJavaSerializer@1e470a51
27-02-2025 13:00:33.955 [main] DEBUG o.e.i.i.s.s.DefaultSerializationProvider.constructSerializer - Serializer for <java.lang.Object> : org.ehcache.impl.serialization.PlainJavaSerializer@6971f5f4
27-02-2025 13:00:33.955 [main] DEBUG o.e.i.i.spi.copy.DefaultCopyProvider.createCopier - Copier for <java.lang.Object> : org.ehcache.impl.copy.SerializingCopier@5b784f16
27-02-2025 13:00:33.955 [main] DEBUG o.e.i.i.spi.copy.DefaultCopyProvider.createCopier - Copier for <java.lang.Object> : org.ehcache.impl.copy.SerializingCopier@21143041
27-02-2025 13:00:33.956 [main] DEBUG org.ehcache.core.StatusTransitioner.debug - {cache-alias=hotel}Initialize successful.
dependencies:
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jcache</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
application.properties:
hibernate.cache.use_second_level_cache=true
hibernate.cache.region.factory_class=org.hibernate.cache.jcache.internal.JCacheRegionFactory
hibernate.javax.cache.uri=ehcache.xml
hibernate.javax.cache.provider=org.ehcache.jsr107.EhcacheCachingProvider
ehcache.xml:
<config 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.xsd">
<cache alias="dictionary">
<expiry>
<tti unit="hours">4</tti>
</expiry>
<heap>10000</heap>
</cache>
<cache alias="hotel">
<expiry>
<tti unit="hours">24</tti>
</expiry>
<heap>200</heap>
</cache>
</config>
Why ehcache config file isn't loading?
Upvotes: 0
Views: 23
Reputation: 359
Changing parameter names solved the problem.
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.jcache.internal.JCacheRegionFactory
spring.jpa.properties.hibernate.javax.cache.provider=org.ehcache.jsr107.EhcacheCachingProvider
spring.jpa.properties.hibernate.javax.cache.uri=ehcache.xml
Because I'm using Java 21 and Spring Boot 3 dependencies in pom.xml also needed change:
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jcache</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<classifier>jakarta</classifier>
</dependency>
Upvotes: 0