无法将数据存储在Redis数据存储中-Spring Boot

时间:2019-03-29 20:18:28

标签: java spring-boot redis spring-data-redis

将数据存储到Redis存储中时出现问题。 Redis已docker化。我不得不提到与Redis的连接已成功打开,并且查询数据的工作非常正常-根本没有问题,但是当我尝试存储数据时,发生了以下异常。

  

例外:

org.springframework.data.keyvalue.core.UncategorizedKeyValueException: nested exception is java.lang.NullPointerException
at org.springframework.data.keyvalue.core.KeyValuePersistenceExceptionTranslator.translateExceptionIfPossible(KeyValuePersistenceExceptionTranslator.java:49)
at org.springframework.data.keyvalue.core.KeyValueTemplate.resolveExceptionIfPossible(KeyValueTemplate.java:484)
at org.springframework.data.keyvalue.core.KeyValueTemplate.execute(KeyValueTemplate.java:379)
at org.springframework.data.keyvalue.core.KeyValueTemplate.update(KeyValueTemplate.java:209)
at org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository.save(SimpleKeyValueRepository.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  

型号:

@RedisHash("TaskSubscriber")
public class TaskSubscriber implements Serializable {

    private static final long serialVersionUID = 20190329202800L;

    private String id;
    private String destination;
    private String username;

    @SuppressWarnings("unused")
    public TaskSubscriber() { }

    public TaskSubscriber(String sessionId, String destination, String username)
    {
        this.id = sessionId;
        this.destination = destination;
        this.username = username;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}
  

存储库:

@Repository
public interface TaskSubscriberRepository extends JpaRepository<TaskSubscriber, String> {

    List<TaskSubscriber> findAllByDestination(String destination);

    List<TaskSubscriber> findAllByUsername(String username);
}

在服务类中,我只是从TaskSubscriber存储库中调用 save 方法,并将TaskSubscriber模型与数据一起传递。

有人知道如何解决此问题吗? 预先谢谢你。

0 个答案:

没有答案