JAVA-31500 :- Upgrade spring-data-redis to Spring Boot 3 (#16057)

This commit is contained in:
Amit Pandey 2024-03-24 19:18:22 +05:30 committed by GitHub
parent f277f6195e
commit 8dcc7d1569
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 30 additions and 22 deletions

View File

@ -10,9 +10,9 @@
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId> <artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath> <relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>
@ -72,12 +72,17 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<verbose>true</verbose>
<fork>false</fork>
<forkCount>0</forkCount> <forkCount>0</forkCount>
<argLine>-Xmx1024m</argLine> <argLine>-Xmx1024m</argLine>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
@ -85,7 +90,8 @@
<cglib.version>3.2.4</cglib.version> <cglib.version>3.2.4</cglib.version>
<nosqlunit.version>0.10.0</nosqlunit.version> <nosqlunit.version>0.10.0</nosqlunit.version>
<embedded-redis.version>0.6</embedded-redis.version> <embedded-redis.version>0.6</embedded-redis.version>
<jedis.version>5.0.2</jedis.version> <jedis.version>4.3.2</jedis.version>
<start-class>com.baeldung.spring.data.redis.SpringRedisApplication</start-class>
</properties> </properties>
</project> </project>

View File

@ -14,7 +14,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext; import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
import javax.annotation.PreDestroy; import jakarta.annotation.PreDestroy;
@Configuration @Configuration
public class RedisConfig { public class RedisConfig {
@ -45,7 +45,7 @@ public class RedisConfig {
@PreDestroy @PreDestroy
public void cleanRedis() { public void cleanRedis() {
factory.getConnection() factory.getConnection().serverCommands()
.flushDb(); .flushDb();
} }
} }

View File

@ -29,9 +29,9 @@ public class RedisConfig {
@Bean @Bean
public RedisTemplate<String, Object> redisTemplate() { public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>(); final RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory()); template.setConnectionFactory(jedisConnectionFactory());
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class)); template.setValueSerializer(new GenericToStringSerializer<>(Object.class));
return template; return template;
} }

View File

@ -2,9 +2,11 @@ package com.baeldung.spring.data.redis.model;
import java.io.Serializable; import java.io.Serializable;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisHash; import org.springframework.data.redis.core.RedisHash;
@RedisHash("Student") @RedisHash("Student")
@RequiredArgsConstructor
public class Student implements Serializable { public class Student implements Serializable {
public enum Gender { public enum Gender {

View File

@ -10,7 +10,7 @@ import java.util.List;
@Service @Service
public class RedisMessageSubscriber implements MessageListener { public class RedisMessageSubscriber implements MessageListener {
public static List<String> messageList = new ArrayList<String>(); public static List<String> messageList = new ArrayList<>();
public void onMessage(final Message message, final byte[] pattern) { public void onMessage(final Message message, final byte[] pattern) {
messageList.add(message.toString()); messageList.add(message.toString());

View File

@ -37,13 +37,13 @@ public class RedisKeyCommandsManualTest {
private ReactiveStringCommands stringCommands; private ReactiveStringCommands stringCommands;
@BeforeClass @BeforeClass
public static void startRedisServer() throws IOException { public static void startRedisServer() {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build(); redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
redisServer.start(); redisServer.start();
} }
@AfterClass @AfterClass
public static void stopRedisServer() throws IOException { public static void stopRedisServer() {
redisServer.stop(); redisServer.stop();
} }

View File

@ -34,13 +34,13 @@ public class RedisTemplateListOpsManualTest {
private ReactiveListOperations<String, String> reactiveListOps; private ReactiveListOperations<String, String> reactiveListOps;
@BeforeClass @BeforeClass
public static void startRedisServer() throws IOException { public static void startRedisServer() {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build(); redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build();
redisServer.start(); redisServer.start();
} }
@AfterClass @AfterClass
public static void stopRedisServer() throws IOException { public static void stopRedisServer() {
redisServer.stop(); redisServer.stop();
} }

View File

@ -37,13 +37,13 @@ public class RedisTemplateValueOpsManualTest {
private ReactiveValueOperations<String, Employee> reactiveValueOps; private ReactiveValueOperations<String, Employee> reactiveValueOps;
@BeforeClass @BeforeClass
public static void startRedisServer() throws IOException { public static void startRedisServer() {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build(); redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
redisServer.start(); redisServer.start();
} }
@AfterClass @AfterClass
public static void stopRedisServer() throws IOException { public static void stopRedisServer() {
redisServer.stop(); redisServer.stop();
} }

View File

@ -33,18 +33,18 @@ public class StudentRepositoryManualTest {
private static redis.embedded.RedisServer redisServer; private static redis.embedded.RedisServer redisServer;
@BeforeClass @BeforeClass
public static void startRedisServer() throws IOException { public static void startRedisServer() {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build(); redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build();
redisServer.start(); redisServer.start();
} }
@AfterClass @AfterClass
public static void stopRedisServer() throws IOException { public static void stopRedisServer() {
redisServer.stop(); redisServer.stop();
} }
@Test @Test
public void whenSavingStudent_thenAvailableOnRetrieval() throws Exception { public void whenSavingStudent_thenAvailableOnRetrieval() {
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1); final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
studentRepository.save(student); studentRepository.save(student);
final Student retrievedStudent = studentRepository.findById(student.getId()).get(); final Student retrievedStudent = studentRepository.findById(student.getId()).get();
@ -52,7 +52,7 @@ public class StudentRepositoryManualTest {
} }
@Test @Test
public void whenUpdatingStudent_thenAvailableOnRetrieval() throws Exception { public void whenUpdatingStudent_thenAvailableOnRetrieval() {
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1); final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
studentRepository.save(student); studentRepository.save(student);
student.setName("Richard Watson"); student.setName("Richard Watson");
@ -62,7 +62,7 @@ public class StudentRepositoryManualTest {
} }
@Test @Test
public void whenSavingStudents_thenAllShouldAvailableOnRetrieval() throws Exception { public void whenSavingStudents_thenAllShouldAvailableOnRetrieval() {
final Student engStudent = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1); final Student engStudent = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
final Student medStudent = new Student("Med2015001", "Gareth Houston", Student.Gender.MALE, 2); final Student medStudent = new Student("Med2015001", "Gareth Houston", Student.Gender.MALE, 2);
studentRepository.save(engStudent); studentRepository.save(engStudent);
@ -73,7 +73,7 @@ public class StudentRepositoryManualTest {
} }
@Test @Test
public void whenDeletingStudent_thenNotAvailableOnRetrieval() throws Exception { public void whenDeletingStudent_thenNotAvailableOnRetrieval() {
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1); final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
studentRepository.save(student); studentRepository.save(student);
studentRepository.deleteById(student.getId()); studentRepository.deleteById(student.getId());