<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/spring-ai-tutorial-07---chat-memory-yh3hsiegf" -->

---
title: Spring AI Tutorial : 07 - Chat Memory | daily.dev
description: A hands-on walkthrough of implementing chat memory in a Spring AI application to overcome the statelessness of LLMs. It covers using the default in-memory...
canonical: https://daily.dev/posts/spring-ai-tutorial-07---chat-memory-yh3hsiegf
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Spring AI Tutorial : 07 - Chat Memory | daily.dev
og:description: A hands-on walkthrough of implementing chat memory in a Spring AI application to overcome the statelessness of LLMs. It covers using the default in-memory...
og:url: https://daily.dev/posts/spring-ai-tutorial-07---chat-memory-yh3hsiegf
og:image: https://api.daily.dev/og/posts/YH3hSIeGf.png
og:image:alt: Spring AI Tutorial : 07 - Chat Memory
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Spring AI Tutorial : 07 - Chat Memory

**[SivaLabs \(YouTube\)](https://daily.dev/sources/sivalabs-youtube)** · 20 min read · 0 upvotes · 0 comments

## Summary

A hands-on walkthrough of implementing chat memory in a Spring AI application to overcome the statelessness of LLMs. It covers using the default in-memory MessageChatMemoryAdvisor to retain conversation context, configuring a JDBC-based ChatMemoryRepository backed by PostgreSQL (via Spring Boot Docker Compose support) for persistent storage, and implementing per-user conversation isolation using cookie-based conversation IDs so multiple clients can maintain separate chat histories.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=LTkch_PO2mM>

## Questions this post answers

### How do I make a Spring AI chatbot remember previous messages in a conversation?

Add Spring AI's MessageChatMemoryAdvisor as a default advisor on the ChatClient, backed by a ChatMemory instance. It automatically appends the last N messages (20 by default) from the conversation history to each new request sent to the LLM, so the model has context from earlier turns without you manually managing history.

_Developers wiring up conversational context in Spring AI can find implementation walkthroughs like this on daily.dev._

### How can I persist Spring AI chat memory to a database instead of storing it in memory?

Use the spring-ai-starter-model-chat-memory-repository-jdbc dependency along with a JDBC driver such as PostgreSQL's, then configure spring.ai.chat.memory.repository.jdbc.initialize-schema=always so Spring AI auto-creates the required table on startup. This swaps the default in-memory ChatMemoryRepository for one backed by a persistent database, so conversation history survives application restarts.

_Teams moving chatbot state from memory to a real database can track patterns like this on daily.dev._

### How do I keep chat conversations separate for different users in a Spring AI chatbot?

Bind a conversation ID cookie (e.g. x-conv-id) per client request; generate a random UUID when the cookie is absent and reuse the existing value otherwise, then pass that ID into the chat memory advisor's conversation parameter. This isolates each user's message history so multiple browsers or clients interacting simultaneously don't share or overwrite each other's context.

_Developers building multi-user chatbots can find isolation techniques like this on daily.dev._

## Similar posts on daily.dev

- [Spring AI : Chat Memory](https://daily.dev/posts/spring-ai-chat-memory-efyzhftcv) · SivaLabs · 2 upvotes · 0 comments
- [Spring AI tutorial: Get started with Spring AI](https://daily.dev/posts/spring-ai-tutorial-get-started-with-spring-ai-phjfbwkwg) · InfoWorld · 0 upvotes · 0 comments
- [Spring AI Series](https://daily.dev/posts/spring-ai-series-j7w3rmryb) · Baeldung · 4 upvotes · 0 comments
- [Building an AI-Powered Operations Assistant with Spring AI and MongoDB Atlas — Part 2: Conversational Memory](https://daily.dev/posts/building-an-ai-powered-operations-assistant-with-spring-ai-and-mongodb-atlas-part-2-conversationa-zq3na1mno) · Foojay.io · 0 upvotes · 0 comments

---

Tags: [#java](https://daily.dev/tags/java), [#postgresql](https://daily.dev/tags/postgresql), [#spring-boot](https://daily.dev/tags/spring-boot), [#spring-ai](https://daily.dev/tags/spring-ai)

[View this post on daily.dev](https://daily.dev/posts/spring-ai-tutorial-07---chat-memory-yh3hsiegf)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Spring AI Tutorial : 07 - Chat Memory","url":"https://daily.dev/posts/spring-ai-tutorial-07---chat-memory-yh3hsiegf","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/spring-ai-tutorial-07---chat-memory-yh3hsiegf"},"datePublished":"2026-09-27T07:26:38.989Z","dateModified":"2026-09-27T07:53:25.292Z","description":"A hands-on walkthrough of implementing chat memory in a Spring AI application to overcome the statelessness of LLMs. It covers using the default in-memory...","image":"https://i.ytimg.com/vi/LTkch_PO2mM/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/LTkch_PO2mM/sddefault.jpg","isAccessibleForFree":true,"articleSection":"SivaLabs (YouTube)","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SivaLabs (YouTube)","logo":"https://media.daily.dev/image/upload/s--8ATVo4an--/f_auto,q_auto/v1790493987/logos/sivalabs-youtube?_a=BAMAMicg0","url":"https://daily.dev/sources/sivalabs-youtube"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/spring-ai-tutorial-07---chat-memory-yh3hsiegf","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"java,postgresql,spring-boot,spring-ai","timeRequired":"PT20M","video":{"@type":"VideoObject","name":"Spring AI Tutorial : 07 - Chat Memory","description":"A hands-on walkthrough of implementing chat memory in a Spring AI application to overcome the statelessness of LLMs. It covers using the default in-memory...","thumbnailUrl":"https://i.ytimg.com/vi/LTkch_PO2mM/sddefault.jpg","uploadDate":"2026-09-27T07:26:38.989Z","duration":"PT20M","url":"https://api.daily.dev/r/YH3hSIeGf","embedUrl":"https://www.youtube.com/embed/LTkch_PO2mM"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SivaLabs (YouTube)","item":"https://daily.dev/sources/sivalabs-youtube"},{"@type":"ListItem","position":3,"name":"Spring AI Tutorial : 07 - Chat Memory"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/spring-ai-tutorial-07---chat-memory-yh3hsiegf#faq","mainEntity":[{"@type":"Question","name":"How do I make a Spring AI chatbot remember previous messages in a conversation?","acceptedAnswer":{"@type":"Answer","text":"Add Spring AI's MessageChatMemoryAdvisor as a default advisor on the ChatClient, backed by a ChatMemory instance. It automatically appends the last N messages (20 by default) from the conversation history to each new request sent to the LLM, so the model has context from earlier turns without you manually managing history. Developers wiring up conversational context in Spring AI can find implementation walkthroughs like this on daily.dev."}},{"@type":"Question","name":"How can I persist Spring AI chat memory to a database instead of storing it in memory?","acceptedAnswer":{"@type":"Answer","text":"Use the spring-ai-starter-model-chat-memory-repository-jdbc dependency along with a JDBC driver such as PostgreSQL's, then configure spring.ai.chat.memory.repository.jdbc.initialize-schema=always so Spring AI auto-creates the required table on startup. This swaps the default in-memory ChatMemoryRepository for one backed by a persistent database, so conversation history survives application restarts. Teams moving chatbot state from memory to a real database can track patterns like this on daily.dev."}},{"@type":"Question","name":"How do I keep chat conversations separate for different users in a Spring AI chatbot?","acceptedAnswer":{"@type":"Answer","text":"Bind a conversation ID cookie (e.g. x-conv-id) per client request; generate a random UUID when the cookie is absent and reuse the existing value otherwise, then pass that ID into the chat memory advisor's conversation parameter. This isolates each user's message history so multiple browsers or clients interacting simultaneously don't share or overwrite each other's context. Developers building multi-user chatbots can find isolation techniques like this on daily.dev."}}]}
```

