Leanpub Header

Skip to main content

Spring AI

A Plain-English Guide for Java Developers

Spring AI
This book is 100% completeLast updated on 2026-09-21

Spring AI gives you one API for chat models, embeddings, vector stores and tools, and swaps the provider with a single property. This book teaches it by building: thirteen chapters, seventeen complete Spring Boot projects, and every program run on a free local model and on a paid cloud model before a word was written about it. Start chapter 1 with no account, no API key and no credit card.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

Use AI models in Java the way you already use databases.

Spring AI gives you one API for chat models, embeddings, vector stores and tools, and swaps the provider with a property. This book teaches it by building, not by listing features: thirteen chapters, seventeen complete Spring Boot projects, and every program run on a free local model and on a paid cloud model before a word was written about it.

WHAT YOU GET

- The complete book as a colour PDF, 354 pages, fixed layout: every diagram, code listing and table exactly as designed

- An EPUB of the same book, for phones and e-readers

- The code: 17 complete Maven projects, one per chapter, free and MIT licensed at https://github.com/raj-ansh/spring-ai-examples

- Appendix A: 113 gotchas with the exact error messages that led to them

- Free updates for this edition, whenever a new version is published

WHAT YOU BUILD

- A first chat program that runs with no API key at all

- Prompts that hold their rules under pressure

- Java objects out of a model, validated, with no string parsing

- A conversation that remembers, without leaking one user into another

- Embeddings, and a search that understands meaning

- A vector store on PostgreSQL and pgvector, in Docker

- Retrieval-augmented generation over your own PDFs

- Tools the model can call, including one that needs your approval first

- An MCP server and client, talking to each other

- A four-layer test suite, two layers of which need no model

- Metrics, traces and a cost meter, per feature

- Timeouts, retries, concurrency limits, redaction and secrets, ready for production

HONEST NOTES

Which versions? Spring AI 2.0.1, Spring Boot 4.1.1, Spring Framework 7.0.9, Java 21. Every number in the book was measured on that stack. Spring AI 2.0 will not load under Spring Boot 3.x at all, and most material published about it online is still pre-2.0 and wrong.

Do I need an API key? No. Every chapter runs on a free local model through Ollama. An OpenAI key is optional, and the book shows the same code on both.

Is the code really complete? Yes: one Maven project per chapter, not snippets. It is public, so you can read it before you buy the book: https://github.com/raj-ansh/spring-ai-examples

Can I read a chapter first? Yes. Chapter 1 is free above, and it is the chapter that gets a working AI program running on your own machine in about fifteen minutes, with no account and no API key.

Why a PDF as well as the EPUB? The figures and listings are laid out for the page, and a fixed-layout PDF keeps them that way, in colour, on any screen. Both files come with the book, so read whichever suits the device.

The paperback and Kindle editions are on Amazon if you prefer print.

Author

About the Author

Rajkumar Panda

Rajkumar is a Java architect with ten years of experience building production systems in Java and Spring Boot, and has worked across PHP, Angular and AWS. He wrote *Spring AI: A Plain-English Guide for Java Developers* the way he learns: by building the thing, running it, and writing down what actually happened, including the parts that failed. Every project in the book runs on a free local model, so any developer canfollow it without a credit card. The code is public at

https://github.com/raj-ansh/spring-ai-examples

Contents

Table of Contents

  • 1. What Spring AI Actually Does
  • 2. Prompts, and What the Model Really Sees
  • 3. ChatClient in a Real Spring Boot App
  • 4. Java Objects, Not Strings
  • 5. Conversations That Remember
  • 6. Embeddings: Teaching a Computer What "Similar" Means
  • 7. Vector Stores: Semantic Search on PostgreSQL
  • 8. RAG: Answering From Your Own Documents
  • 9. Tool Calling: Letting the Model Use Your Code
  • 10. MCP: Sharing Tools Between AI Applications
  • 11. Testing What You Cannot Predict
  • 12. Observability, Cost and Latency
  • 13. Preparing for Production
  • Appendix A. Gotchas, and What Fixed Them

Get the free Community Edition

You can get the free Community Edition in PDF or EPUB just by sharing your name and email address with the author.

 

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub