Skip to content

About

A collection of code examples used in SPRING AI A DEVELOPERS HANDBOOK.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring AI – A Developer's Handbook: companion code

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.

Modules

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.

Run the offline tests

No model, network or API key is needed:

./mvnw test

Run one chapter (-am also builds the modules it depends on):

./mvnw -pl ch15-rag -am test

Tip: on a small machine, build one module at a time. A full multi-module build can use a lot of memory.

Tests that need something running

  • Live tests (tagged live) call a real model and are skipped by default. Run them with the live profile:

    ollama pull llama3.2
    ollama pull nomic-embed-text
    ./mvnw -pl ch06-chatclient -am test -Plive

    The 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-stores test, which starts pgvector with Testcontainers.

Run the applications

./mvnw -pl ch02-first-app spring-boot:run

The 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.

Errata

If something in the book does not match this code, please open an issue and label it errata.

Licence

MIT, see LICENSE.

About

A collection of code examples used in SPRING AI A DEVELOPERS HANDBOOK.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages