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>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
<relativePath>../../parent-boot-3</relativePath>
</parent>
<dependencies>
@ -72,12 +72,17 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>false</fork>
<forkCount>0</forkCount>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
</plugins>
</build>
@ -85,7 +90,8 @@
<cglib.version>3.2.4</cglib.version>
<nosqlunit.version>0.10.0</nosqlunit.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>
</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.StringRedisSerializer;
import javax.annotation.PreDestroy;
import jakarta.annotation.PreDestroy;
@Configuration
public class RedisConfig {
@ -45,7 +45,7 @@ public class RedisConfig {
@PreDestroy
public void cleanRedis() {
factory.getConnection()
factory.getConnection().serverCommands()
.flushDb();
}
}

View File

@ -29,9 +29,9 @@ public class RedisConfig {
@Bean
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.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
template.setValueSerializer(new GenericToStringSerializer<>(Object.class));
return template;
}

View File

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

View File

@ -10,7 +10,7 @@ import java.util.List;
@Service
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) {
messageList.add(message.toString());

View File

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

View File

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

View File

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

View File

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