Skip to content

Commit

Permalink
Add ehcache rule
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Manuel Leflet Estrada <[email protected]>
  • Loading branch information
jmle committed Nov 4, 2024
1 parent 718747d commit d4f3c81
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
- ruleID: spring-framework-5.x-to-6.0-removed-apis-00001
category: mandatory
effort: 5
labels:
- konveyor.io/source=spring5
- konveyor.io/target=spring6+
when:
or:
- java.referenced:
pattern: org.springframework.cache.ehcache*
location: IMPORT
- java.dependency:
name: net.sf.ehcache.ehcache
upperbound: 2.10.9.2
description: Spring Framework 6.0 has dropped support for EhCache 2.x
message: |
The org.springframework.cache.ehcache package has been removed as it was providing support for
Ehcache 2.x - with this version, `net.sf.ehcache` is using Java EE APIs and is about to be End Of Life'd.
Ehcache 3 is the direct replacement. Please revisit your dependency management to use `org.ehcache:ehcache`
(with the jakarta classifier) instead and look into the official migration guide or reach out to the ehcache
community for assistance.
There is no renewed support or helpers for EhCache 3.0 integration anymore, and the `org.springframework.cache.ehcache`
package has been removed. Instead, you can either use the JCache API (JSR-107) or EhCache 3's native API.
If you want to use the JCache (JSR-107) integration, Spring's caching abstraction allows for it:
1. Enable Caching in Spring as usual:
```java
@Configuration
@EnableCaching
public class CacheConfig {
// CacheManager bean configuration goes here
}
```
2. Configure a JCache `CacheManager`:
```java
import javax.cache.Caching;
import javax.cache.spi.CachingProvider;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.jcache.JCacheCacheManager;
@Configuration
@EnableCaching
public class CacheConfig {
@Bean
public JCacheCacheManager cacheManager() {
CachingProvider cachingProvider = Caching.getCachingProvider();
javax.cache.CacheManager ehCacheManager = cachingProvider.getCacheManager();
return new JCacheCacheManager(ehCacheManager);
}
}
```
Additionally, you may need to adapt your Ehcache 2.x XML configuration to be compatible with Ehcache 3.x
if you were previously using XML-based cache configurations.
For specifics on how to migrate from Ehcache 2 to 3, please check the link provided.
links:
- title: 'Spring 6.0 migration guide'
url: https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-6.0-Release-Notes#removed-apis
- title: 'Ehcache 2 to 3 migration guide'
url: https://www.ehcache.org/documentation/3.10/migration-guide.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>spring-boot-ehcache2-example</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
</parent>

<dependencies>
<!-- Spring Boot Starter Web for creating a web application -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Spring Boot Starter Cache for enabling caching support -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>

<!-- EhCache 2.x dependency -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.9.2</version> <!-- Latest EhCache 2.x version -->
</dependency>

<!-- Spring Boot Starter Test for testing purposes -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.konveyor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableCaching
public class EhCache2Application {
public static void main(String[] args) {
SpringApplication.run(EhCache2Application.class, args);
}

@Bean
public EhCacheCacheManager cacheManager() {
return new EhCacheCacheManager();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
rulesPath: ../spring-framework-5.x-to-6.0-baseline.yaml
providers:
- name: java
dataPath: ./data
dataPath: ./data/baseline
- name: builtin
dataPath: ./data
dataPath: ./data/baseline
tests:
- ruleID: spring-framework-5.x-to-6.0-baseline-00001
testCases:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
rulesPath: ../spring-framework-5.x-to-6.0-removed-apis.yaml
providers:
- name: java
dataPath: ./data/removed-apis/ehcache-app
tests:
- ruleID: spring-framework-5.x-to-6.0-removed-apis-00001
testCases:
- name: tc-1
analysisParams:
mode: "source-only"
hasIncidents:
exactly: 2

0 comments on commit d4f3c81

Please sign in to comment.