Build AI-Powered Java Apps Fast with Spring AI Alibaba: Features & Demo

Spring AI Alibaba is an open‑source Java framework that integrates Alibaba Cloud's large‑model services with Spring AI, offering high‑level abstractions for chat models, prompts, function calling, RAG, and conversation memory, and includes a complete ticket‑assistant example with code snippets.

Alibaba Cloud Developer
Alibaba Cloud Developer
Alibaba Cloud Developer
Build AI-Powered Java Apps Fast with Spring AI Alibaba: Features & Demo

Project Overview

Spring AI Alibaba is an open‑source AI application framework for Java developers, built on Spring AI and deeply integrated with Alibaba Cloud's Tongyi series models and cloud‑native infrastructure, enabling rapid development of generative AI applications.

Core Features

Designed specifically for Spring/Java developers; using it feels like building a regular Spring Boot application, so the learning curve is low.

Provides high‑level abstractions for chat model interaction, prompt templates, function calling, chat memory, and retrieval‑augmented generation (RAG).

Offers out‑of‑the‑box integration with Tongyi models and best‑practice deployment tooling such as gateways, configuration management, observability, and cloud‑native support.

Key Concepts

Chat Model

Abstracts interaction with large language models, supporting text, image, audio, and multimodal inputs, with synchronous, asynchronous, and streaming communication modes.

Prompt

Manages composite prompts containing multiple roles (System, User, Assistant). Spring AI provides a Prompt Template abstraction that lets developers define reusable templates and substitute variables at runtime.

Structured Output

Converts the often unstructured responses from LLMs into defined Java objects automatically, by injecting format hints into the prompt and mapping the result to Java beans.

Function Calling

Registers Java methods as callable tools; the framework injects function definitions into the prompt, receives a tool‑execution request from the model, executes the method, and feeds the result back to the model for a final answer.

Retrieval‑Augmented Generation (RAG)

Combines offline vector‑store indexing of domain‑specific knowledge with runtime retrieval to enrich prompts, allowing the model to answer questions with up‑to‑date, rule‑based information.

Example: Intelligent Ticket Assistant

The demo builds a ticket‑booking assistant that can understand user intent, maintain multi‑turn conversation, apply airline‑specific rules via RAG, and perform actions such as booking, changing, or canceling tickets through function calls.

Setup

Add the starter dependency:

<dependency>
    <groupId>com.alibaba.ai</groupId>
    <artifactId>spring-ai-alibaba-starter</artifactId>
    <version>1.0.0-M2</version>
</dependency>

Configure the API key:

spring:
  ai:
    dashscope:
      api-key: ${AI_DASHSCOPE_API_KEY}

Create a Spring REST controller that injects ChatClient and forwards user input to the model:

@RestController
public class ChatController {
    private final ChatClient chatClient;
    public ChatController(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }
    @GetMapping("/chat")
    public String chat(String input) {
        return this.chatClient.prompt()
                .user(input)
                .call()
                .content();
    }
}

Build a ChatClient with system prompt, advisors for memory, vector store, RAG, and declared functions:

this.chatClient = modelBuilder
        .defaultSystem("""
            You are a friendly support agent for Funnair airline.
            Always obtain booking number and customer name before providing information.
            Verify that any change complies with airline policies and obtain consent for fees.
            Use the provided functions to get, change, or cancel bookings.
            Respond in Chinese. Current date: {current_date}.
            """)
        .defaultAdvisors(
            new PromptChatMemoryAdvisor(chatMemory),
            new VectorStoreChatMemoryAdvisor(vectorStore),
            new QuestionAnswerAdvisor(vectorStore, SearchRequest.defaults()),
            new LoggingAdvisor())
        .defaultFunctions("getBookingDetails", "changeBooking", "cancelBooking")
        .build();

The assistant now supports multi‑turn dialogue, RAG‑enhanced rule checking, and function‑driven ticket operations.

Roadmap

Future plans include richer prompt‑template management, event‑driven AI applications, broader vector‑store support, function‑execution deployment modes, observability enhancements, AI‑agent node capabilities (e.g., rate limiting, model switching), and expanded developer toolsets.

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.

JavaRAGFunction Callingspring-aiChatbotAI Framework
Alibaba Cloud Developer
Written by

Alibaba Cloud Developer

Alibaba's official tech channel, featuring all of its technology innovations.

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.