Every code listing in the book comes from this repository. It is compiled and tested against Spring AI 2.0.1 and Spring Boot 4.0.8. It targets Java 17 and is tested on Java 17 and 21.
| Module | Chapter | Topic |
|---|---|---|
ch02-first-app |
2 | First application |
ch03-core-model |
3 | Messages, prompts, options, responses |
ch04-providers |
4 | Providers and switching between them |
ch05-prompts |
5 | Prompt templates |
ch06-chatclient |
6 | ChatClient |
ch07-structured-output |
7 | Structured output |
ch08-advisors |
8 | Advisors |
ch09-chat-memory |
9 | Chat memory |
ch10-images |
10 | Image generation |
ch11-audio-moderation |
11 | Audio and moderation |
ch12-embeddings |
12 | Embeddings |
ch13-vector-stores |
13 | Vector stores (pgvector via Testcontainers) |
ch14-ingestion |
14 | Document ingestion |
ch15-rag |
15 | Retrieval-augmented generation |
ch16-tool-calling |
16 | Tool calling |
ch17-mcp-server, ch17-mcp-client |
17 | Model Context Protocol |
ch18-agentic-patterns |
18 | Workflows and agents |
ch19-observability |
19 | Metrics and tracing |
ch20-testing-evaluation |
20 | Testing and evaluation (uses ch15-rag) |
ch21-security |
21 | Security |
ch22-deployment |
22 | Dockerfile, Kubernetes, Compose |
ch23-capstone |
23 | Multi-tenant document assistant |
sample-data/ holds the invented "Acme Cloud" documents used in the RAG chapters.
No model, network or API key is needed:
./mvnw testRun one chapter (-am also builds the modules it depends on):
./mvnw -pl ch15-rag -am testTip: on a small machine, build one module at a time. A full multi-module build can use a lot of memory.
-
Live tests (tagged
live) call a real model and are skipped by default. Run them with theliveprofile:ollama pull llama3.2 ollama pull nomic-embed-text ./mvnw -pl ch06-chatclient -am test -PliveThe chapters name the exact models they used. Paid-provider examples (chapters 10, 11) are mocked in the tests.
-
Docker must be running for the
ch13-vector-storestest, which starts pgvector with Testcontainers.
./mvnw -pl ch02-first-app spring-boot:runThe MCP server (ch17-mcp-server) and client (ch17-mcp-client) and the capstone use their own ports; see each module's application.yml and the chapter text. Chapter 22 shows how to build and run the container image.
If something in the book does not match this code, please open an issue and label it errata.
MIT, see LICENSE.