I have the folowing hibernate (legacy (non-JPA)) dependencies defined while using Spring 5.X version
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.6.5.Final</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.9.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Since I’m moving to Spring 6.X framework. I got it changed to following:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core-jakarta</artifactId>
<version>5.6.15.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jcache</artifactId>
<version>6.2.6.Final</version>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.10.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
And in the applicationContext.xml
, I got the following :
<bean id="ehcache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:config-location="/WEB-INF/applicationContext-ehcache.xml"
p:shared="true" />
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheCacheManager"
p:cache-manager-ref="ehcache" />
changed to the following :
<bean id="ehcache"
class="org.springframework.cache.jcache.JCacheManagerFactoryBean"
p:config-location="/WEB-INF/applicationContext-ehcache.xml"
p:shared="true" />
<bean id="cacheManager"
class="org.springframework.cache.jcache.JCacheCacheManager"
p:cache-manager-ref="ehcache" />
Do I need to make any changes in the following existing applicationContext-ehcache.xml ?
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="classpath:ehcache.xsd" updateCheck="false">
<diskStore path="java.io.tmpdir" />
<defaultCache maxElementsInMemory="1000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" />
<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="50" eternal="false" timeToLiveSeconds="120"
overflowToDisk="true" />
<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="5000" eternal="true" overflowToDisk="true" />
<cache name="com.pending.model.Test" maxElementsInMemory="10000"
eternal="false" timeToIdleSeconds="600" timeToLiveSeconds="1200"
overflowToDisk="false" />
<cache name="com.pending.model.TestGroup" maxElementsInMemory="1000"
eternal="false" timeToIdleSeconds="600" timeToLiveSeconds="1200"
overflowToDisk="false" />
<cache name="com.pending.model.Type"
maxElementsInMemory="1000" eternal="false" timeToIdleSeconds="600"
timeToLiveSeconds="1200" overflowToDisk="false" />
</ehcache>
I haven’t made any changes yet but I am getting all sorts of errors like following:
[INFO] ERROR - ContextLoader.initWebApplicationContext(308) | Context initialization failed [INFO] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceSTR' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Error creating bean with name 'org.springframework.cache.config.internalCacheAdvisor': Cannot resolve reference to bean 'org.springframework.cache.annotation.AnnotationCacheOperationSource#0' while setting bean property 'cacheOperationSource' [INFO] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.config.internalCacheAdvisor': Cannot resolve reference to bean 'org.springframework.cache.annotation.AnnotationCacheOperationSource#0' while setting bean property 'cacheOperationSource'
Here’s how the bean in applicationContext-hibernate.xml
looks like:
<bean id="dataSourceSTR"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>#{T(com.sql.DataSourceData).getDataSourceData('str').getProperty(T(com.sql.DataSourceData).DRIVER)}</value>
</property>
<property name="url">
<value>#{T(com.sql.DataSourceData).getDataSourceData('str').getProperty(T(com.sql.DataSourceData).URL)}</value>
</property>
<property name="username">
<value>#{T(com.sql.DataSourceData).getDataSourceData('str').getProperty(T(com.sql.DataSourceData).USERNAME)}</value>
</property>
<property name="password">
<value>#{T(com.sql.DataSourceData).getDataSourceData('str').getProperty(T(com.sql.DataSourceData).PASSWORD)}</value>
</property>
</bean>
Similarly there are other errors as well but if I can get the above one fixed, I think other will follow the same. What am I doing wrong here? If for some reason I should not use org.hibernate.orm
for jcache
, what could be an alternative ? Thanks!