Spring AI 1.1 GA: Quick Start Guide for Building Java AI Applications

This article introduces Spring AI, explains its purpose as a standardized Java framework for AI integration, highlights the new Model Context Protocol and expanded model support in version 1.1 GA, and provides a step‑by‑step tutorial—including dependencies, configuration, and code examples—to help developers quickly build AI‑powered applications.

Senior Xiao Ying
Senior Xiao Ying
Senior Xiao Ying
Spring AI 1.1 GA: Quick Start Guide for Building Java AI Applications

What Is Spring AI?

Spring AI is an official Spring framework that standardizes AI application development for Java developers, offering a Spring‑Boot‑like, modular approach that eliminates repetitive integration code across different AI providers.

Key Highlights of the 1.1 GA Release

The milestone 1.1 GA release (expected end of 2025) introduces the Model Context Protocol (MCP), an open protocol that standardizes connections between AI models and external data sources or tools, solving the "data silo" problem and enabling complex AI agents.

Additional enhancements include stronger support for Google Gemini, Anthropic Claude, prompt caching, and ReAct Agent capabilities, significantly improving the framework’s maturity and feature set.

Core Concepts and Architecture

Spring AI’s design provides a unified abstraction layer so developers learn a single API and can switch model providers effortlessly. Its main components are:

Abstract model interfaces with multiple implementations for easy component replacement.

Auto‑configuration that creates ChatModel or ChatClient beans automatically when a provider starter (e.g., OpenAI) is on the classpath.

Prompt templates ( PromptTemplate) that allow dynamic placeholders such as {variable} for runtime substitution.

Quick Start Guide

Integrating Spring AI into a project involves three steps:

Add the dependency

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
    <version>{latest stable version}</version>
</dependency>

Configure the application

spring:
  ai:
    openai:
      api-key: ${YOUR_API_KEY}
      base-url: ${API_BASE_URL} # optional, defaults to OpenAI endpoint
      chat:
        options:
          model: gpt-4o
          temperature: 0.7

These settings go into application.yml and can be adapted for compatible services such as DeepSeek or Alibaba Cloud.

Write the code

@RestController
public class AIController {
    private final ChatClient chatClient;

    public AIController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }

    @GetMapping("/ai/chat")
    public String chat(@RequestParam("message") String message) {
        return this.chatClient.prompt()
            .user(message)
            .call()
            .content();
    }
}

Inject ChatClient (a higher‑level wrapper over ChatModel ) to interact with the AI service.

Important Notes

ChatClient vs. ChatModel: ChatClient offers a richer, chainable API and is generally more convenient for typical use cases, while ChatModel can be used directly in simple scenarios.

Auto‑Configuration: Adding a provider starter automatically creates the necessary ChatModel or ChatClient beans; no manual configuration classes are required—just use @Autowired to inject them.

Core Concept Details

ChatModel vs. ChatClient ChatModel is the engine that provides basic AI capabilities. ChatClient builds on top of it, adding features like a steering wheel and seats, making development smoother.

Auto‑Configuration When a starter dependency (e.g., OpenAI) is present, Spring Boot auto‑creates ChatModel or ChatClient instances, eliminating the need for custom configuration classes.

PromptTemplate Spring AI supplies PromptTemplate to construct prompts flexibly; placeholders like {variable} are replaced at runtime with actual values.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaSpring BootSpring AIModel Context ProtocolAI integrationPromptTemplateChatClient
Senior Xiao Ying
Written by

Senior Xiao Ying

Dedicated to sharing Java backend technical experience and original tutorials, offering career transition advice and resume editing. Recognized as a rising star in CSDN's Java backend community and ranked Top 3 in the 2022 New Star Program for Java backend.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.