Spring AI's ChatClient Turns a Java CRUD App Into a Poetry Bot in Under 50 Lines
Spring AI 1.0 gives the enormous Java/Spring ecosystem a stable, RestTemplate-like on-ramp to LLMs. Teams that already run Spring Boot in production can add AI calls without leaving their stack, their dependency-injection patterns, or their configuration-management habits.
A new Spring AI 1.0 starter—spring-ai-starter-model-openai—replaces the hand-rolled HTTP, JSON parsing, and error handling that Java developers previously needed to call an LLM. The ChatClient API mirrors the ergonomics of RestTemplate: a builder-injected bean, a prompt().user().call().content() chain, and model-provider details pushed entirely into application.yml. The walkthrough targets Tongyi Qianwen via Alibaba Cloud's OpenAI-compatible endpoint, using an environment-variable API key to avoid credential leaks.
The tutorial also draws a clean line between Spring AI (the portable interface layer) and Spring AI Alibaba (an Alibaba Cloud-specific superset with Graph workflow support), framing the choice as JDBC vs. a vendor driver. A refactor step separates concerns into a Controller and Service, producing a REST endpoint that turns a query parameter into an AI-generated poem.
Common early pitfalls are catalogued: the base-url path must end at /compatible-mode without a trailing /v1, hardcoded keys in YAML invite credential theft, and model names like qwen-plus vs. qwen-max carry real performance differences.
Spring AI's design choice to mirror RestTemplate lowers the cognitive overhead for millions of Spring developers, but it also inherits RestTemplate's limitations—blocking calls by default, no built-in retry or circuit-breaking, and a builder that hides the underlying HTTP client configuration.
The JDBC-vs-driver analogy for Spring AI vs. Spring AI Alibaba is useful but incomplete: JDBC drivers don't add entirely new execution engines like a Graph workflow, so the Alibaba variant is more of a platform SDK than a drop-in driver.
Hardcoding prompts inside Java source files is called out as a problem to solve in the next installment, which signals that the Spring AI ecosystem still lacks a mature, community-standard prompt templating story comparable to what Python frameworks offer.