liveBook · Manning

Chapter 1: Getting started with Spring AI

What you will learn in chapter 1 of Spring AI in Action

The introduction explains what generative AI offers users and developers, and why Spring AI makes it accessible in Java applications.

After this chapter you will be able to

Section by section

Introduction

The introduction explains what generative AI offers users and developers, and why Spring AI makes it accessible in Java applications.

Key terms: generative AI, natural language prompts, large language models (LLMs), applications, menus and forms, Spring AI, Spring, Spring Boot, Java

1.1 Hello, Spring AI!

This section introduces Spring AI as a provider-independent client abstraction for sending prompts to AI models and receiving generated responses.

Key terms: Spring AI, client abstraction, AI providers, LLMs, prompt, generated response, LLM, AI provider, natural language, sentiment

1.1.1 Initializing the project

The section explains how to initialize the book’s Spring AI application with Spring Initializr and the dependencies and build settings it needs.

Key terms: Spring Boot starter dependencies, autoconfiguration, Spring Initializr, Groovy-based Gradle, Spring Web, Spring AI’s OpenAI starter dependencies, Project Metadata, Spring AI version 1.0.3, bill of materials (BOM), build.gradle

1.1.2 Submitting prompts

This section builds a question-answering REST endpoint with Spring AI’s ChatClient and explains how to supply an OpenAI API key without committing it to source control.

Key terms: SpringAiBoardGameService, ChatClient.Builder, ChatClient, prompt(), user(), call(), AskController, POST, /ask, Question

1.1.3 Writing a test

The section explains why live LLM responses are difficult to assert against and shows how to test a Spring AI service using a deterministic WireMock response.

Key terms: LLM, nondeterministic, completion request, WireMock, @EnableWireMock, @SpringBootTest, spring.ai.openai.base-url, /v1/chat/completions, askQuestion()

1.1.4 Trying it out

Shows how to try the Spring AI question-and-answer application and explains why repeated requests can produce different answers.

Key terms: Spring Boot application, POST request, /ask, JSON, question, generative AI, nondeterministic, probabilistic, prompts

1.2 Choosing a model

This section explains the range of models available through Spring AI, what to consider when choosing one, and why changing providers usually requires little application-code change.

Key terms: OpenAI starter, OpenAI-compatible APIs, price, context window, tokens, training, capabilities, starter dependency, credentials, application configuration

1.2.1 Configuring OpenAI models

This section explains how Spring AI connects to OpenAI models, how to select a model, and what changes when using Azure OpenAI.

Key terms: OpenAI integration, starter, ChatClient.Builder, ChatClient, prompt(), GPT-4o mini, GPT-4.1, GPT-4.1 nano, spring.ai.openai.chat.options.model, Azure OpenAI

1.2.2 Serving models locally with Ollama

This section explains how to run Ollama models locally and configure Spring AI to use them.

Key terms: Ollama, ollama pull, Ollama starter dependency, open-source LLMs, model size, hardware, API key, Mistral 7B, spring.ai.ollama.chat.model, spring.ai.ollama.init.pull-model-strategy

1.3 Previewing Spring AI’s capabilities

The section explains why Spring AI applications may need more than a single text prompt and response, introducing templates, conversational context, document access, and application tools.

Key terms: prompt templates, placeholders, parameter values, context, chat history, chat memory, retrieval-augmented generation (RAG), documents, training, RAG

1.4 Summary

Where this is used later

Concepts explained in this chapter

Chapter 2: Evaluating generated responses →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.