23 Eylül 2021 Perşembe

SpringSession SessionRepository Arayüzü

Giriş
Şu satırı dahil ederiz
import org.springframework.session.SessionRepository;
Örnek
Şöyle yaparız
import org.springframework.session.MapSession; @Repository
@RequiredArgsConstructor
public class IgniteSessionRepository implements SessionRepository<MapSession> {
  private final SessionRepository sessionRepo;

  @Value("${sessions.maxInactiveInterval:1800}")
  private final long maxInactiveInterval;

  @Override
  public MapSession createSession() {
    MapSession session = new MapSession();

    session.setMaxInactiveInterval(Duration.ofMinutes(maxInactiveInterval));

    return session;
  }

  @Override
  public void save(MapSession session) {
    sessionRepo.save(session.getId(), session);
  }

  @Override
  public MapSession findById(String id) {
    return sessionRepo.findById(id).orElseThrow();
  }

  @Override
  public void deleteById(String id) {
    sessionRepo.deleteById(id);
  }
}

Hiç yorum yok:

Yorum Gönder