{"id":41396,"date":"2025-08-01T17:46:58","date_gmt":"2025-08-01T12:16:58","guid":{"rendered":"https:\/\/mobisoftinfotech.com\/resources\/?p=41396"},"modified":"2025-10-15T15:20:33","modified_gmt":"2025-10-15T09:50:33","slug":"spring-ai-llm-integration-spring-boot","status":"publish","type":"post","link":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot","title":{"rendered":"Mastering Spring AI: Easily Add LLM Smarts to Your Spring Boot Applications"},"content":{"rendered":"<h2 class=\"wp-block-heading\"><strong>Introduction<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>The Rise of AI APIs<\/strong><\/h3>\n\n\n\n<p>Over the past few years, AI has rapidly transitioned from research labs to real-world applications. Thanks to AI APIs from providers like OpenAI, Google Gemini, Anthropic Claude, and others, developers can now access powerful large language models (LLMs) with just a few lines of code, making Spring Boot AI integration increasingly practical.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>The New Problem: Integration Complexity<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">However, with that ease comes a new kind of complexity:<\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>Every provider has its SDKs<\/li>\n\n\n\n<li>Different authentication flows<\/li>\n\n\n\n<li>Inconsistent response formats<\/li>\n\n\n\n<li>Manual code duplication for switching vendors<\/li>\n<\/ul>\n\n\n\n<p class=\"para-after-small-heading\">This makes supporting multiple providers, or switching between them, tedious and error-prone, especially for those exploring Spring AI OpenAI integration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>Enter Spring AI: A Unified Abstraction<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">That\u2019s where Spring AI comes in. Developed by the Spring team, this project brings the Spring Boot developer experience to LLMs by offering:<\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>A consistent programming model<\/li>\n\n\n\n<li>Unified configuration patterns<\/li>\n\n\n\n<li>Easy switching between providers like OpenAI and Gemini<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"478\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-architecture-llm-java.png\" alt=\"Spring AI architecture for LLM applications\" class=\"wp-image-41421\" title=\"Spring AI Architecture for Java LLM Integration\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"478\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20478%22%3E%3C%2Fsvg%3E\" alt=\"Spring AI architecture for LLM applications\" class=\"wp-image-41421 lazyload\" title=\"Spring AI Architecture for Java LLM Integration\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-architecture-llm-java.png\"><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What You&#8217;ll Learn in This Blog<\/strong><\/h3>\n\n\n\n<p>In this post, we\u2019ll walk through a working Spring Boot POC that integrates both OpenAI and Google Gemini. You\u2019ll learn how to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use Spring AI\u2019s ChatClient abstraction<\/li>\n\n\n\n<li>Swap providers with just a parameter change<\/li>\n\n\n\n<li>Avoid vendor lock-in from day one using Spring AI LLM practices<\/li>\n<\/ul>\n\n\n\n<p>Whether you&#8217;re exploring providers or aiming to build a flexible AI-powered backend, this post is for you. If you&#8217;re planning to apply LLMs in real-world apps, consider<a href=\"https:\/\/mobisoftinfotech.com\/services\/artificial-intelligence?utm_source=blog&amp;utm_campaign=spring-ai-llm-integration-spring-boot\"> AI and machine learning consulting<\/a> to help architect scalable, intelligent solutions tailored to your domain.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is Spring AI?<\/strong><\/h2>\n\n\n\n<p>Spring AI is a relatively new addition to the Spring ecosystem that brings AI model integration, especially large language models (LLMs), into the familiar Spring Boot world. Just like Spring abstracts database access, messaging, and security, Spring AI does the same for AI and ML capabilities.&nbsp;<\/p>\n\n\n\n<p>Instead of wrestling with REST APIs, raw payloads, and provider-specific quirks, Spring AI provides clean, Spring-style abstractions for interacting with models like GPT, Gemini, or Azure OpenAI.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Why Spring AI Matters?<\/strong><\/h3>\n\n\n\n<p>At its core, Spring AI lets you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use a standardized interface (ChatClient) to interact with multiple providers<\/li>\n\n\n\n<li>Avoid boilerplate code<\/li>\n\n\n\n<li>Easily switch between LLM providers (OpenAI, Gemini, Azure, etc.) with minimal config changes using Spring AI Java LLM integration techniques<\/li>\n<\/ul>\n\n\n\n<p>This means you focus on business logic, not SDK wiring.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mobisoftinfotech.com\/solutions\/private-llm-implementation-deployment?utm_source=blog_cta&amp;utm_campaign=spring-ai-llm-integration-spring-boot\"><noscript><img decoding=\"async\" width=\"855\" height=\"363\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/private-llm-spring-ai-integration.png\" alt=\"Enterprise-grade private LLM implementation with Spring AI\" class=\"wp-image-41422\" title=\"Custom LLM Integration Solutions\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"363\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20363%22%3E%3C%2Fsvg%3E\" alt=\"Enterprise-grade private LLM implementation with Spring AI\" class=\"wp-image-41422 lazyload\" title=\"Custom LLM Integration Solutions\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/private-llm-spring-ai-integration.png\"><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Core Features<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Unified ChatClient Abstraction<\/strong><\/h4>\n\n\n\n<p>Spring AI provides a common ChatClient API for sending prompts and receiving responses, regardless of which model or provider is behind the scenes.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">chatClient<\/span><span class=\"hljs-selector-class\">.prompt<\/span>(\"<span class=\"hljs-selector-tag\">Your<\/span> <span class=\"hljs-selector-tag\">input<\/span>\")<span class=\"hljs-selector-class\">.call<\/span>()<span class=\"hljs-selector-class\">.content<\/span>();<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This enables plug-and-play flexibility when changing backends and supports the growing interest in how to integrate LLM in Spring Boot.<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Easy Switching Between Providers<\/strong><\/h4>\n\n\n\n<p>You can swap between OpenAI or Google Gemini just by changing the parameter in the request. No rewrites.<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Auto-Configuration for Popular Providers<\/strong><\/h4>\n\n\n\n<p>Spring AI supports the following providers out of the box:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>OpenAI via spring-ai-starter-model-openai<\/li>\n\n\n\n<li>Google Gemini (Vertex AI) via spring-ai-starter-model-vertex-ai-gemini<\/li>\n<\/ul>\n\n\n\n<p>The right beans and defaults are wired automatically based on your Maven dependencies.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Spring Boot Starter-Style Integration<\/strong><\/h4>\n\n\n\n<p>Following the \u201cconvention over configuration\u201d philosophy, Spring AI:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Uses familiar Spring Boot conventions<\/li>\n\n\n\n<li>Registers beans automatically<\/li>\n\n\n\n<li>Supports externalized configuration (application.properties \/ application.yml)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What Makes Spring AI Shine<\/strong><\/h3>\n\n\n\n<p>With Spring AI, integrating LLMs becomes as effortless as configuring a data source or message queue. You don\u2019t need to deal with REST templates, auth headers, or manual JSON parsing; just drop in the dependency and start prompting using Spring AI with OpenAI LLM.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why Use Spring AI?<\/strong><\/h2>\n\n\n\n<p>As AI APIs like OpenAI, Gemini, and Azure OpenAI continue to evolve, Java developers face a tough question:<\/p>\n\n\n\n<p>How can we integrate LLMs flexibly without vendor lock-in or duplicated effort?<\/p>\n\n\n\n<p>Spring AI answers this with a clean, unified, and production-ready abstraction. Here\u2019s why it\u2019s a great fit for modern AI apps:<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>Avoid Vendor Lock-In with a Consistent API<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">Each provider has its own SDK quirks, auth flow, and response format. That leads to tightly coupled code and headaches when switching providers.<\/p>\n\n\n\n<p class=\"para-after-small-heading\">Spring AI solves this with a common ChatClient interface:<\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">chatClient<\/span><span class=\"hljs-selector-class\">.prompt<\/span>(\"<span class=\"hljs-selector-tag\">Generate<\/span> <span class=\"hljs-selector-tag\">a<\/span> <span class=\"hljs-selector-tag\">summary<\/span>\")<span class=\"hljs-selector-class\">.call<\/span>()<span class=\"hljs-selector-class\">.content<\/span>();<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"para-after-small-heading\">This makes your application vendor-agnostic, perfect for evaluating providers or complying with regional\/data regulations. Examples of this flexibility can be seen in Spring AI LLM integration use cases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>Minimal Learning Curve for Spring Developers<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">If you already know how to build REST APIs, configure beans in Spring Boot, you already know 90% of what it takes to use Spring AI.<\/p>\n\n\n\n<p class=\"para-after-small-heading\">No need to learn the intricacies of each LLM provider\u2019s SDK.<\/p>\n\n\n\n<p class=\"para-after-small-heading\"><strong>Spring AI fits naturally into familiar Spring concepts:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>Auto-configured models via Spring Boot starters<\/li>\n\n\n\n<li>Externalized config via application.yml<\/li>\n\n\n\n<li>Standard annotations like @Bean<\/li>\n<\/ul>\n\n\n\n<p class=\"para-after-small-heading\">This dramatically reduces time-to-POC and onboarding effort even in complex scenarios like Spring AI RAG pipeline implementations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>Clean Integration Without Boilerplate<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">Integrating LLMs the traditional way involves writing verbose REST client logic:<\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>Manual JSON payloads<\/li>\n\n\n\n<li>HTTP headers for API keys<\/li>\n\n\n\n<li>Response parsing and error handling<\/li>\n<\/ul>\n\n\n\n<p class=\"para-after-small-heading\">With Spring AI, all of that disappears behind a single clean abstraction:<\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">String<\/span> reply = chatClient.prompt(<span class=\"hljs-string\">\"What are the&nbsp; features&nbsp; of Java?\"<\/span>).call().content();<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"para-after-small-heading\">No need for RestTemplate, WebClient, or third-party SDKs. It\u2019s just plug-and-play, even supporting advanced use cases like a Spring AI vector store RAG example.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>Unified Error Handling Across Providers<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">Each LLM provider returns different error formats (e.g. HTTP 429 for rate limits, or custom model not found errors).<\/p>\n\n\n\n<p class=\"para-after-small-heading\">Spring AI normalizes these responses into a consistent exception hierarchy, so your app can handle failures uniformly, regardless of the provider:<\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">try<\/span> {\n    chatClient.prompt(<span class=\"hljs-string\">\"Your Prompt\"<\/span>).call();\n} <span class=\"hljs-keyword\">catch<\/span> (AiClientException ex) {\n    log.warn(<span class=\"hljs-string\">\"AI call failed: {}\"<\/span>, ex.getMessage());\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>Key Takeaways<\/strong><\/h4>\n\n\n\n<h5 class=\"wp-block-heading h5-list\"><strong>Consistent API Across Providers<\/strong><\/h5>\n\n\n\n<p>Use the same ChatClient code whether you&#8217;re calling OpenAI, Gemini, or Azure; no provider-specific logic is needed.<\/p>\n\n\n\n<h5 class=\"wp-block-heading h5-list\"><strong>Switch Models via parameter, Not Code Changes<\/strong><\/h5>\n\n\n\n<p>Configure once and use different agents.<\/p>\n\n\n\n<h5 class=\"wp-block-heading h5-list\"><strong>Minimal Learning Curve for Spring Devs<\/strong><\/h5>\n\n\n\n<p>If you know Spring Boot, you know Spring AI; it reuses familiar concepts like @Bean, application.yml, and auto-config.<\/p>\n\n\n\n<h5 class=\"wp-block-heading h5-list\"><strong>No Boilerplate, Just Business Logic<\/strong><\/h5>\n\n\n\n<p>Forget about writing HTTP clients and response parsers. One method call does the job:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">chatClient<\/span><span class=\"hljs-selector-class\">.prompt<\/span>(\"<span class=\"hljs-selector-tag\">Your<\/span> <span class=\"hljs-selector-tag\">question<\/span>\")<span class=\"hljs-selector-class\">.call<\/span>()<span class=\"hljs-selector-class\">.content<\/span>();<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h5 class=\"wp-block-heading h5-list\"><strong>Unified Error Handling Out of the Box<\/strong><\/h5>\n\n\n\n<p>Spring AI consolidates diverse provider errors into a unified exception model, making it easier to integrate retries, circuit breakers, and logging.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Spring AI Building Blocks (Under the Hood)<\/strong><\/h2>\n\n\n\n<p>Now that you\u2019ve seen why Spring AI helps simplify LLM integration, let\u2019s unpack how it works. Behind its clean API, Spring AI provides a well-structured set of components that align naturally with Spring Boot development patterns a central concept in Spring Boot AI architecture.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>ChatClient:&nbsp; The Unified Gateway<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">At the core of Spring AI is the ChatClient, a single interface that abstracts away all provider-specific logic. Whether you&#8217;re talking to OpenAI, Google Gemini, or Azure, your code stays the same:<\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">String<\/span> reply = chatClient\n    .prompt(<span class=\"hljs-string\">\"Summarize this article\"<\/span>)\n    .call()\n    .content();<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"para-after-small-heading\">This makes it incredibly simple to implement Spring AI LLM integration with minimal friction: SDKs or response formats, just prompt, call, and consume the result.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>Provider-Specific Model Beans (For Fine-Grained Control)<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">When you need more control, Spring AI exposes model-specific beans for Spring AI Java LLM integration use cases:<\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>OpenAiChatModel<\/li>\n\n\n\n<li>VertexAiGeminiChatModel<\/li>\n\n\n\n<li>AzureOpenAiChatModel<\/li>\n<\/ul>\n\n\n\n<p class=\"para-after-small-heading\"><strong>These beans let you configure:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>Temperature<\/li>\n\n\n\n<li>Max tokens<\/li>\n\n\n\n<li>Model version<\/li>\n\n\n\n<li>Streaming or non-streaming mode<\/li>\n<\/ul>\n\n\n\n<p class=\"para-after-small-heading\">This layered model lets developers fine-tune behavior while still benefiting from high-level Spring AI prompt engineering abstractions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>Auto-Configuration via Starters<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">Spring AI follows Spring Boot conventions: include the right starter, and everything \u201cjust works.\u201d<\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dependency<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>org.springframework.ai<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>spring-ai-starter-model-openai<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">dependency<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"para-after-small-heading\">This ease of integration makes Spring AI tutorial adoption fast and accessible, especially for projects exploring how to integrate LLM in Spring Boot.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>Seamless Integration with the Spring Ecosystem<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\"><strong>Spring AI plugs in smoothly with other Spring modules:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li><strong>Spring Web<\/strong> \u2013 Build RESTful endpoints that call LLMs<br><\/li>\n\n\n\n<li><strong>Spring Security<\/strong> \u2013 Secure access to your AI endpoints<br><\/li>\n\n\n\n<li><strong>Spring Boot Actuator &amp; Micrometer<\/strong> \u2013 Monitor and trace AI usage<br><\/li>\n\n\n\n<li><strong>Spring Retry \/ Resilience4j<\/strong> \u2013 Add retry logic or circuit breakers around LLM calls<\/li>\n<\/ul>\n\n\n\n<p class=\"para-after-small-heading\">This makes Spring AI a great fit whether you&#8217;re prototyping or building something for production.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Overview of the POC App<\/strong><\/h2>\n\n\n\n<p>To demonstrate the practical value of Spring AI, this Proof of Concept (POC) application showcases a simple yet flexible architecture that dynamically integrates with multiple LLM providers, including OpenAI and Google Gemini (Vertex AI), within a single Spring Boot AI application.&nbsp;<\/p>\n\n\n\n<p>This example is intentionally lightweight and focused, allowing you to grasp the core mechanics of Spring AI without being distracted by unrelated boilerplate or UI elements. It&#8217;s a great Spring AI tutorial for building foundational understanding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>Tech Stack<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">The POC leverages the latest tools in the Spring ecosystem along with standard modern Java:<\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li><strong>Java 17: <\/strong>&nbsp;Modern language features, better performance, and long-term support (LTS)<\/li>\n\n\n\n<li><strong>Spring Boot 3.5.0: <\/strong>&nbsp;Latest version with support for Jakarta EE 10, enhanced observability, and better native compilation compatibility<\/li>\n\n\n\n<li><strong>Spring AI (SNAPSHOT version): <\/strong>&nbsp;Pulling in the latest Spring AI features, including support for OpenAI, Spring AI LLM, Gemini, and more.<\/li>\n\n\n\n<li><strong>Maven<\/strong>: For dependency and build management<\/li>\n<\/ul>\n\n\n\n<p class=\"para-after-small-heading\">This stack is fully open-source, well-supported, and ready for rapid prototyping or production evolution.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>What the App Does<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">At a high level, the application exposes a single REST API endpoint:<\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\"><span><code class=\"hljs\">GET \/ai?prompt=YourText&amp;model=openai<\/code><\/span><\/pre>\n\n\n<p class=\"para-after-small-heading\">You can send any natural language prompt to this endpoint along with the model to be used, and it will respond with an AI-generated reply based on the requested model.<\/p>\n\n\n\n<p class=\"para-after-small-heading\"><strong>But here\u2019s the key feature: <\/strong>The app dynamically switches between OpenAI and Gemini based on the request.<\/p>\n\n\n\n<p class=\"para-after-small-heading\"><strong>This means:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>No need for separate codebases or microservices per provider<\/li>\n\n\n\n<li>Just configure the required properties and the appropriate bean<\/li>\n\n\n\n<li>The correct ChatClient is used based on the parameter model<\/li>\n\n\n\n<li>You\u2019re free to test, compare, or switch models with zero logic changes<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading h3-list\"><strong>Minimal Configuration Per Provider<\/strong><\/h3>\n\n\n\n<p class=\"para-after-small-heading\">One of the strengths of Spring AI, and a major goal of this POC, is to demonstrate how little configuration is needed to get started with different AI providers:<\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>For OpenAI, you just provide your API key via application.properties<\/li>\n\n\n\n<li>For Gemini, the setup points to Google\u2019s Vertex AI with project ID and credentials, but still uses a similar ChatClient interface<\/li>\n<\/ul>\n\n\n\n<p class=\"para-after-small-heading\">There\u2019s no need to manually build HTTP requests, set headers, or parse responses; the Spring AI abstraction handles it all. You focus on the prompt design and the response, not the plumbing. This highlights how Spring AI Prompt Design Patterns can simplify implementation.<\/p>\n\n\n\n<p class=\"para-after-small-heading\"><strong>This POC is ideal for:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>Developers evaluating AI providers<\/li>\n\n\n\n<li>Teams building platform-agnostic AI capabilities<\/li>\n\n\n\n<li>Use cases where flexibility, speed, and clean separation of concerns matter, such as in Spring AI RAG pipeline development<\/li>\n<\/ul>\n\n\n\n<p class=\"para-after-small-heading\">In the next section, we&#8217;ll walk through how code is structured, including configuration files and key Java components.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Code Walkthrough<\/strong><\/h2>\n\n\n\n<p>Let\u2019s take a look under the hood of the POC and understand how Spring AI is integrated using standard Spring Boot conventions. The setup is simple, modular, and designed to make switching between LLM providers as painless as possible.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>POM Configuration<\/strong><\/h3>\n\n\n\n<p>The project uses Maven to manage dependencies.<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Import the Spring AI BOM<\/strong><\/h4>\n\n\n\n<p class=\"para-after-small-heading\">The Spring AI project is still evolving, so you&#8217;ll want to import the Spring AI BOM (Bill of Materials) to ensure all dependencies stay aligned and compatible:<\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dependencyManagement<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dependencies<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dependency<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>org.springframework.ai<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>spring-ai-bom<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">version<\/span>&gt;<\/span>1.0.0-SNAPSHOT<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">version<\/span>&gt;<\/span> <span class=\"hljs-comment\">&lt;!-- or latest available --&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">type<\/span>&gt;<\/span>pom<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">type<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">scope<\/span>&gt;<\/span>import<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">scope<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">dependency<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">dependencies<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">dependencyManagement<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"para-after-small-heading\">This ensures consistent versioning across all Spring AI modules.<\/p>\n\n\n\n<p class=\"para-after-small-heading\">Also, some of the model integrations may currently exist only in snapshot or milestone versions.&nbsp;<\/p>\n\n\n\n<p class=\"para-after-small-heading\"><strong>To resolve these, add the following repositories to your <\/strong><strong>pom.xml<\/strong><strong>:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">repositories<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">repository<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">id<\/span>&gt;<\/span>spring-snapshots<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">id<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">name<\/span>&gt;<\/span>Spring Snapshots<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">name<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">url<\/span>&gt;<\/span>https:\/\/repo.spring.io\/snapshot<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">url<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">snapshots<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">enabled<\/span>&gt;<\/span>true<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">enabled<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">snapshots<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">repository<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">repository<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">id<\/span>&gt;<\/span>spring-milestones<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">id<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">name<\/span>&gt;<\/span>Spring Milestones<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">name<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">url<\/span>&gt;<\/span>https:\/\/repo.spring.io\/milestone<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">url<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">snapshots<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">enabled<\/span>&gt;<\/span>false<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">enabled<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">snapshots<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">repository<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">repositories<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Add Provider-Specific Starters<\/strong><\/h4>\n\n\n\n<p class=\"para-after-small-heading\">Next, declare the dependencies for the LLM providers you want to support:<\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-comment\">&lt;!-- OpenAI Starter --&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dependency<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>org.springframework.ai<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>spring-ai-starter-model-vertex-ai-gemini<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">dependency<\/span>&gt;<\/span>\n\n<span class=\"hljs-comment\">&lt;!-- Vertex AI Gemini Starter --&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dependency<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>org.springframework.ai<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>spring-ai-starter-model-vertex-ai-gemini<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">dependency<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"para-after-small-heading\">These starters support Spring AI Java LLM Integration and include model classes, auto-configuration, and ChatClient support.&nbsp;<\/p>\n\n\n\n<p class=\"para-after-small-heading\">Now, running <code>mvn spring-boot:run<\/code> will load the configurations and beans.<\/p>\n\n\n\n<p class=\"para-after-small-heading\">(We will go over an extra step required for Vertex Gemini for credentials)<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Application Properties<\/strong><\/h4>\n\n\n\n<p class=\"para-after-small-heading\">Spring AI uses auto-configuration to connect to LLM providers. You just need to supply basic credentials and metadata in your <code>application.properties<\/code> or <code>application.yml<\/code>.<\/p>\n\n\n\n<h5 class=\"wp-block-heading para-after-small-heading\">For OpenAI:<\/h5>\n\n\n<pre class=\"wp-block-code para-after-small-heading\"><span><code class=\"hljs\">spring.ai.openai.api-key=YOUR_OPENAI_KEY<\/code><\/span><\/pre>\n\n\n<p class=\"para-after-small-heading\">You can retrieve your OpenAI key from:<a href=\"https:\/\/platform.openai.com\/account\/api-keys\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"> https:\/\/platform.openai.com\/account\/api-keys<\/a><\/p>\n\n\n\n<h5 class=\"wp-block-heading para-after-small-heading\"><strong>For Google Gemini (Vertex AI):<\/strong><\/h5>\n\n\n<pre class=\"wp-block-code para-after-small-heading\"><span><code class=\"hljs\">spring.ai.vertex.ai.gemini.api-endpoint=us-central1-aiplatform.googleapis.com\nspring.ai.vertex.ai.gemini.project-id=YOUR_PROJECT_ID\nspring.ai.vertex.ai.gemini.location=us-central1<\/code><\/span><\/pre>\n\n\n<p class=\"para-after-small-heading\">If you are using an application.yaml,&nbsp;<\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">spring<\/span>:\n  <span class=\"hljs-selector-tag\">ai<\/span>:\n    <span class=\"hljs-selector-tag\">openai<\/span>:\n      <span class=\"hljs-selector-tag\">api-key<\/span>: <span class=\"hljs-selector-tag\">YOUR_OPENAI_KEY<\/span>\n    <span class=\"hljs-selector-tag\">vertex<\/span>:\n      <span class=\"hljs-selector-tag\">ai<\/span>:\n        <span class=\"hljs-selector-tag\">gemini<\/span>:\n          <span class=\"hljs-selector-tag\">api-endpoint<\/span>: <span class=\"hljs-selector-tag\">us-central1-aiplatform<\/span><span class=\"hljs-selector-class\">.googleapis<\/span><span class=\"hljs-selector-class\">.com<\/span>\n          <span class=\"hljs-selector-tag\">project-id<\/span>: <span class=\"hljs-selector-tag\">YOUR_PROJECT_ID<\/span>\n          <span class=\"hljs-selector-tag\">location<\/span>: <span class=\"hljs-selector-tag\">us-central1<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"para-after-small-heading\">In addition to these properties, make sure your application can authenticate using a service account JSON key (explained in the next section). This is required by Google Cloud SDKs.<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Note on Region &amp; Endpoint<\/strong><\/h4>\n\n\n\n<p class=\"para-after-small-heading\">The <code>location<\/code> and <code>api-endpoint<\/code> values in the Gemini configuration (e.g., <code>us-central1<\/code>) depend on where your Vertex AI resources are deployed.<br>If your GCP project is using a different region (e.g., <code>europe-west4<\/code>, <code>asia-southeast1<\/code>), update both:<\/p>\n\n\n<pre class=\"wp-block-code para-after-small-heading\"><span><code class=\"hljs\">spring.ai.vertex.ai.gemini.location=your-region\nspring.ai.vertex.ai.gemini.api-endpoint=your-region-aiplatform.googleapis.com<\/code><\/span><\/pre>\n\n\n<p class=\"para-after-small-heading\">You can verify your region in the Google Cloud Console under Vertex AI &gt; Locations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Setting Up Credentials<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"503\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-openai-integration-code.png\" alt=\"Spring AI OpenAI integration in Spring Boot code example\" class=\"wp-image-41423\" title=\"Spring AI OpenAI Code Integration\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"503\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20503%22%3E%3C%2Fsvg%3E\" alt=\"Spring AI OpenAI integration in Spring Boot code example\" class=\"wp-image-41423 lazyload\" title=\"Spring AI OpenAI Code Integration\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-openai-integration-code.png\"><\/figure>\n\n\n\n<p>To interact securely with OpenAI and Google Gemini (via Vertex AI), you\u2019ll need to set up authentication credentials for both providers. This section walks through how to do that.<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>OpenAI API Key<\/strong><\/h4>\n\n\n\n<p class=\"para-after-small-heading\">Spring AI uses your OpenAI API key to authenticate requests to OpenAI\u2019s servers.<\/p>\n\n\n\n<p class=\"h5-list\">Steps:<\/p>\n\n\n\n<h5 class=\"wp-block-heading h5-list\"><strong>Create\/Open an Account<\/strong><\/h5>\n\n\n\n<p>Go to<a href=\"https:\/\/platform.openai.com\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"> https:\/\/platform.openai.com<\/a> and sign in or create a free account.<\/p>\n\n\n\n<h5 class=\"wp-block-heading h5-list\"><strong>Generate API Key<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Navigate to your Account Settings &gt; API Keys<\/li>\n\n\n\n<li>Click \u201c+ Create new secret key\u201d<\/li>\n\n\n\n<li>Copy and save the key securely (you won\u2019t see it again)<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Add to Spring Boot config<\/strong><\/h4>\n\n\n\n<p>In your application.properties:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">spring.ai.openai.api-key=sk-XXXXXXXXXXXXXXXXXXXXXXXX<\/code><\/span><\/pre>\n\n\n<p><strong>Note: <\/strong>Do not commit this key to Git. Use .gitignore and .env files when possible, or externalize it using environment variables for production environments.<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Google Gemini (Vertex AI) Setup<\/strong><\/h4>\n\n\n\n<p>Gemini via Vertex AI requires more configuration due to GCP\u2019s IAM and security model. Spring AI uses the official Google SDK under the hood, which authenticates using a service account JSON key file.<\/p>\n\n\n\n<h5 class=\"wp-block-heading para-after-small-heading\"><strong>Steps:<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"para-after-small-heading\"><strong>Create a Google Cloud Project<\/strong>\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>Go to https:\/\/console.cloud.google.com<\/li>\n\n\n\n<li>Click on \u201cNew Project\u201d<\/li>\n\n\n\n<li>Give it a name (e.g., springai-demo)<\/li>\n\n\n\n<li>Note down the Project ID, you&#8217;ll need it for the&nbsp;<br>Application.properties<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li class=\"para-after-small-heading\"><strong>Enable Vertex AI API<\/strong>\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>Go to APIs &amp; Services &gt; Library<\/li>\n\n\n\n<li>Search for \u201cVertex AI API\u201d<\/li>\n\n\n\n<li>Click Enable<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li class=\"para-after-small-heading\"><strong>Create a Service Account<\/strong>\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>Navigate to IAM &amp; Admin &gt; Service Accounts<\/li>\n\n\n\n<li>Click \u201cCreate Service Account\u201d<\/li>\n\n\n\n<li>Assign it a name like springai-service<\/li>\n\n\n\n<li>Under &#8220;Role&#8221;, choose:<br>Vertex AI &gt; Vertex AI User<\/li>\n\n\n\n<li>Complete creation<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>Download Credentials (JSON)\n<ul class=\"wp-block-list para-after-small-heading\">\n<li>After creating the account, go to the Keys tab<\/li>\n\n\n\n<li>Click \u201cAdd Key\u201d &gt; \u201cCreate New Key\u201d &gt; JSON<\/li>\n\n\n\n<li>Download and securely store this .json file<br><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Set the Environment Variable<br>Spring AI (via Google SDK) looks for the credentials file via an environment variable:<br><br><code>export GOOGLE_APPLICATION_CREDENTIALS=\/path\/to\/your\/credentials.json<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"para-after-small-heading\">If you&#8217;re using an IDE like IntelliJ or Eclipse, ensure this environment variable is passed to the runtime configuration of your app.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Summary<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>OpenAI: <\/strong>Uses a simple API key<\/li>\n\n\n\n<li><strong>Gemini:<\/strong> Requires service account authentication via a JSON key file<\/li>\n\n\n\n<li>Both can be seamlessly configured through Spring AI using minimal setup<\/li>\n<\/ul>\n\n\n\n<p>This authentication setup ensures that your app can securely interact with LLMs while keeping your credentials out of the source code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>ChatClientConfig: Multi-Model Client Configuration<\/strong><\/h3>\n\n\n\n<p>The <code>ChatClientConfig <\/code>class defines multiple <code>ChatClient<\/code> beans, each associated with a different AI provider. These beans are registered under specific names (&#8220;<code>openai<\/code>&#8220;, &#8220;<code>gemini<\/code>&#8220;), allowing the application to dynamically select the appropriate client at runtime based on incoming API parameters.<\/p>\n\n\n\n<p><strong>ChatClientConfig:&nbsp;<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">import<\/span> <span class=\"hljs-selector-tag\">org<\/span><span class=\"hljs-selector-class\">.springframework<\/span><span class=\"hljs-selector-class\">.ai<\/span><span class=\"hljs-selector-class\">.chat<\/span><span class=\"hljs-selector-class\">.client<\/span><span class=\"hljs-selector-class\">.ChatClient<\/span>;\n<span class=\"hljs-selector-tag\">import<\/span> <span class=\"hljs-selector-tag\">org<\/span><span class=\"hljs-selector-class\">.springframework<\/span><span class=\"hljs-selector-class\">.ai<\/span><span class=\"hljs-selector-class\">.openai<\/span><span class=\"hljs-selector-class\">.OpenAiChatModel<\/span>;\n<span class=\"hljs-selector-tag\">import<\/span> <span class=\"hljs-selector-tag\">org<\/span><span class=\"hljs-selector-class\">.springframework<\/span><span class=\"hljs-selector-class\">.ai<\/span><span class=\"hljs-selector-class\">.vertexai<\/span><span class=\"hljs-selector-class\">.gemini<\/span><span class=\"hljs-selector-class\">.VertexAiGeminiChatModel<\/span>;\n<span class=\"hljs-selector-tag\">import<\/span> <span class=\"hljs-selector-tag\">org<\/span><span class=\"hljs-selector-class\">.springframework<\/span><span class=\"hljs-selector-class\">.context<\/span><span class=\"hljs-selector-class\">.annotation<\/span><span class=\"hljs-selector-class\">.Bean<\/span>;\n<span class=\"hljs-selector-tag\">import<\/span> <span class=\"hljs-selector-tag\">org<\/span><span class=\"hljs-selector-class\">.springframework<\/span><span class=\"hljs-selector-class\">.context<\/span><span class=\"hljs-selector-class\">.annotation<\/span><span class=\"hljs-selector-class\">.Configuration<\/span>;\n\n<span class=\"hljs-keyword\">@Configuration<\/span>\npublic class ChatClientConfig {\n\n<span class=\"hljs-keyword\">@Bean<\/span>(name = <span class=\"hljs-string\">\"openai\"<\/span>)\n    ChatClient openAiChatClient(OpenAiChatModel model) {\n        <span class=\"hljs-selector-tag\">return<\/span> <span class=\"hljs-selector-tag\">ChatClient<\/span><span class=\"hljs-selector-class\">.builder<\/span>(<span class=\"hljs-selector-tag\">model<\/span>)<span class=\"hljs-selector-class\">.build<\/span>();\n    }\n\n    <span class=\"hljs-keyword\">@Bean<\/span>(name = <span class=\"hljs-string\">\"gemini\"<\/span>)\n    ChatClient geminiChatClient(VertexAiGeminiChatModel model) {\n        <span class=\"hljs-selector-tag\">return<\/span> <span class=\"hljs-selector-tag\">ChatClient<\/span><span class=\"hljs-selector-class\">.builder<\/span>(<span class=\"hljs-selector-tag\">model<\/span>)<span class=\"hljs-selector-class\">.build<\/span>();\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>Explanation:<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Both <code>ChatClient<\/code> instances are registered as Spring beans, each with a unique name.<\/li>\n\n\n\n<li>These named beans correspond to different Spring AI LLM model implementations: OpenAI and Vertex AI Gemini.<\/li>\n\n\n\n<li>Instead of using conditional bean creation or environment-based selection, the application loads all supported clients during startup, supporting a multi-model Spring AI configuration.<\/li>\n\n\n\n<li>At runtime, the appropriate <code>ChatClient<\/code> is selected by looking up the bean from the Spring context using the model name provided by the user (for example, via a request parameter).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Data Transfer Objects (DTOs)<\/strong><\/h3>\n\n\n\n<p>Since we&#8217;re now using a POST-based interaction that accepts input and returns a structured output, we need two simple DTOs to represent the request and response formats.<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>AIRequest<\/strong><\/h4>\n\n\n\n<p>This class captures the input payload sent by the client, including the prompt and the name of the AI <code>model<\/code> to use.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">AIRequest<\/span> <\/span>{\n    <span class=\"hljs-keyword\">private<\/span> String prompt;\n    <span class=\"hljs-keyword\">private<\/span> String model;\n\n    <span class=\"hljs-comment\">\/\/ Getters and setters<\/span>\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>AIResponse<\/strong><\/h4>\n\n\n\n<p>This class defines the structure of the response returned by the API. It includes the name of the AI model used and the generated response content.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">AIResponse<\/span> <\/span>{\n    <span class=\"hljs-keyword\">private<\/span> String model;\n    <span class=\"hljs-keyword\">private<\/span> String response;\n\n    <span class=\"hljs-comment\">\/\/ Constructor, getters<\/span>\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>These DTOs support clean, testable API logic and support Spring AI prompt engineering patterns by isolating input\/output<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>REST Controller: Unified Endpoint for Both Providers<\/strong><\/h3>\n\n\n\n<p>Here&#8217;s the AIController that interacts with the user via a simple Spring AI with an OpenAI LLM endpoint:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> com.mobisoftinfotech.springai.dto.AIRequest;\n<span class=\"hljs-keyword\">import<\/span> com.mobisoftinfotech.springai.dto.AIResponse;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.ai.chat.client.ChatClient;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.web.bind.annotation.*;\n\n<span class=\"hljs-keyword\">import<\/span> java.util.Map;\n\n@RestController\n@RequestMapping(<span class=\"hljs-string\">\"\/ai\"<\/span>)\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">AIController<\/span> <\/span>{\n\n\tprivate final <span class=\"hljs-built_in\">Map<\/span>&lt;<span class=\"hljs-built_in\">String<\/span>, ChatClient&gt; chatClients;\n\n\tpublic AIController(<span class=\"hljs-built_in\">Map<\/span>&lt;<span class=\"hljs-built_in\">String<\/span>, ChatClient&gt; chatClients) {\n\t\t<span class=\"hljs-keyword\">this<\/span>.chatClients = chatClients;\n\t}\n\n\t@PostMapping\n\tpublic AIResponse getAIResponse(@RequestBody AIRequest request) {\n\t\t<span class=\"hljs-built_in\">String<\/span> modelKey = request.getModel() != <span class=\"hljs-literal\">null<\/span> ? request.getModel().toLowerCase() : <span class=\"hljs-string\">\"openai\"<\/span>;\n\t\tChatClient client = chatClients.get(modelKey);\n\n\t\t<span class=\"hljs-keyword\">if<\/span> (client == <span class=\"hljs-literal\">null<\/span>) {\n\t\t\t<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">new<\/span> AIResponse(modelKey, <span class=\"hljs-string\">\"Unsupported model: \"<\/span> + modelKey);\n\t\t}\n\n\t\t<span class=\"hljs-built_in\">String<\/span> output = client.prompt(request.getPrompt() != <span class=\"hljs-literal\">null<\/span> ? request.getPrompt() : <span class=\"hljs-string\">\"Hello AI!\"<\/span>).call().content();\n\n\t\t<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">new<\/span> AIResponse(modelKey, output);\n\t}\n\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>Explanation:<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This controller is designed to support multiple AI providers dynamically at runtime.<\/li>\n\n\n\n<li>Instead of being tied to a specific provider, it receives the desired model name (e.g., OpenAI, Gemini) along with the prompt as part of the request body. All available ChatClient instances are injected into the controller as a map, keyed by their model names, showcasing how to perform Spring AI Java LLM integration.<\/li>\n\n\n\n<li>At runtime, the controller uses the <code>model<\/code> field from the request to look up the corresponding <code>ChatClient<\/code> and forward the prompt to it. If the requested model is not supported, the controller returns an appropriate message.<\/li>\n\n\n\n<li>This design decouples the controller from any specific AI provider and enables seamless switching or testing of different models through simple client-side parameters, without restarting or redeploying the application. It&#8217;s an example of a Spring Boot AI setup supporting dynamic model selection.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Hit the Endpoint<\/strong><\/h3>\n\n\n\n<p>Once the app is running, you can interact with the AI using a simple HTTP POST request:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">curl -X POST http:<span class=\"hljs-comment\">\/\/localhost:8080\/ai \\<\/span>\n  -H <span class=\"hljs-string\">\"Content-Type: application\/json\"<\/span> \\\n  -d <span class=\"hljs-string\">'{\n    \"prompt\": \"What day is today?\",\n    \"model\": \"gemini\"\n}'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Response:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\n  <span class=\"hljs-attr\">\"model\"<\/span>: <span class=\"hljs-string\">\"gemini\"<\/span>,\n  <span class=\"hljs-attr\">\"response\"<\/span>: <span class=\"hljs-string\">\"Today is Sunday, October 15th, 2023.\"<\/span>\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This call sends your prompt to the AI model and returns its response. These APIs can also power <a href=\"https:\/\/mobisoftinfotech.com\/services\/mobile-app-development-company?utm_source=blog&amp;utm_campaign=spring-ai-llm-integration-spring-boot\">mobile apps powered by LLM backends<\/a> for real-time user experiences.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"800\" height=\"471\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-prompt-engineering-workflow.jpg\" alt=\" Spring AI prompt engineering workflow example\" class=\"wp-image-41484\" title=\"Prompt Engineering with Spring AI\"><\/noscript><img decoding=\"async\" width=\"800\" height=\"471\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%20471%22%3E%3C%2Fsvg%3E\" alt=\" Spring AI prompt engineering workflow example\" class=\"wp-image-41484 lazyload\" title=\"Prompt Engineering with Spring AI\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-prompt-engineering-workflow.jpg\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Beyond the POC: Advanced Use Cases &amp; What\u2019s Next<\/strong><\/h2>\n\n\n\n<p>Once your basic integration with OpenAI or Gemini is working, Spring AI tutorial features provide powerful capabilities that enable real-world, production-ready applications. These include advanced prompting patterns, structured output, contextual memory, and streaming, all while keeping your code clean and idiomatic for Spring Boot.<\/p>\n\n\n\n<p>Here are some areas worth exploring:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Embeddings &amp; Vector Databases (RAG)<\/strong><\/h3>\n\n\n\n<p>The Spring AI embedding configuration tutorial helps you implement embedding models to convert text into vector representations. This is essential for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Semantic search<\/li>\n\n\n\n<li>Document similarity<\/li>\n\n\n\n<li>Retrieval-Augmented Generation (RAG)<\/li>\n<\/ul>\n\n\n\n<p>You can store these embeddings in vector databases such as PGVector, Milvus, Qdrant, or Redis Vector Search. At query time, Spring AI RAG pipeline logic fetches relevant context based on vector similarity, which is then injected into the prompt for more accurate, context-aware responses.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">EmbeddingModel model = ...;\n<span class=\"hljs-keyword\">List<\/span>&lt;Double&gt; embedding = model.embed(<span class=\"hljs-string\">\"Spring AI is amazing\"<\/span>).getEmbedding();<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This is part of how Spring AI vector store RAG example scenarios work in real-world search use cases. If your enterprise demands higher control or privacy, you can also<a href=\"https:\/\/mobisoftinfotech.com\/solutions\/private-llm-implementation-deployment?utm_source=blog_cta&amp;utm_campaign=spring-ai-llm-integration-spring-boot\"> deploy private LLMs with spring boot<\/a> to ensure secure, on-premise AI deployments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Prompt Templating &amp; Structured Output<\/strong><\/h3>\n\n\n\n<p>Hardcoding prompts quickly becomes unmanageable. Spring AI supports:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Prompt templates<\/strong> (text files or annotated classes)<\/li>\n\n\n\n<li><strong>Dynamic variable injection<\/strong><\/li>\n\n\n\n<li><strong>Output parsers<\/strong> for mapping responses to Java objects<\/li>\n<\/ul>\n\n\n\n<p>This enables safer, reusable, and testable prompt patterns and makes structured outputs (e.g., JSON into Java POJOs) easier to handle.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">PromptTemplate template = <span class=\"hljs-keyword\">new<\/span> PromptTemplate(<span class=\"hljs-string\">\"Translate '{{text}}' to Spanish\"<\/span>);\n<span class=\"hljs-built_in\">String<\/span> rendered = template.render(<span class=\"hljs-built_in\">Map<\/span>.of(<span class=\"hljs-string\">\"text\"<\/span>, <span class=\"hljs-string\">\"Hello World\"<\/span>));\n\nJsonOutputParser&lt;Person&gt; parser = <span class=\"hljs-keyword\">new<\/span> JsonOutputParser&lt;&gt;(Person.class);\nPerson person = parser.parse(llmResponse);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><strong>Streaming with Server-Sent Events (SSE)<\/strong><\/h3>\n\n\n\n<p>For real-time user interfaces or chatbots, token-by-token streaming creates a better user experience. Most providers support it, and Spring AI integrates this via Project Reactor:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-keyword\">@GetMapping<\/span>(value = <span class=\"hljs-string\">\"\/ai\/stream\"<\/span>, produces = MediaType.TEXT_EVENT_STREAM_VALUE)\npublic Flux&lt;String&gt; streamResponse(@RequestParam String prompt) {\n    <span class=\"hljs-selector-tag\">return<\/span> <span class=\"hljs-selector-tag\">chatClient<\/span><span class=\"hljs-selector-class\">.prompt<\/span>()\n                     <span class=\"hljs-selector-class\">.user<\/span>(<span class=\"hljs-selector-tag\">prompt<\/span>)\n                     <span class=\"hljs-selector-class\">.stream<\/span>()\n                     <span class=\"hljs-selector-class\">.map<\/span>(<span class=\"hljs-selector-tag\">ChatResponse<\/span><span class=\"hljs-selector-pseudo\">::content)<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To ensure visibility and performance tracking in production,<a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-development\/opentelemetry-java-spring-boot-integration?utm_source=blog&amp;utm_campaign=spring-ai-llm-integration-spring-boot\"> monitoring Spring Boot-based AI services<\/a> is recommended to capture streaming response times, token generation delays, and error trends.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Tool Use &amp; Agent-Like Workflows (Experimental)<\/strong><\/h3>\n\n\n\n<p>Spring AI is evolving toward LLM agents that can decide when to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Call APIs<\/li>\n\n\n\n<li>Perform calculations<\/li>\n\n\n\n<li>Search databases or trigger downstream actions<\/li>\n<\/ul>\n\n\n\n<p>This is similar to LangChain\u2019s tool calling or OpenAI\u2019s function calling. While still experimental, it lays the foundation for agent-like systems with multi-step reasoning and dynamic tool orchestration.&nbsp;<\/p>\n\n\n\n<p>When orchestrating long-running or complex LLM processes, consider<a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial?utm_source=blog&amp;utm_campaign=spring-ai-llm-integration-spring-boot\"> distributed workflow management<\/a> using sagas or event-driven patterns.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Lessons Learned from the POC<\/strong><\/h3>\n\n\n\n<p>During this project, a few consistent takeaways emerged:<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Rapid productivity with model-agnostic design<\/strong><\/h4>\n\n\n\n<p>The <code>ChatClient<\/code> abstraction allows integration with multiple AI providers (like OpenAI and Gemini) with minimal configuration. By injecting named beans and selecting the appropriate one at runtime, we can switch providers without altering core business logic.<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Spring idioms = low friction<\/strong><\/h4>\n\n\n\n<p>If you&#8217;re comfortable with Spring Boot, working with Spring AI feels natural. From @Bean definitions to structured configuration, everything follows familiar Spring patterns.<\/p>\n\n\n\n<h4 class=\"wp-block-heading h4-list\"><strong>Focus on business logic, not infrastructure<\/strong><\/h4>\n\n\n\n<p>We didn\u2019t have to write custom HTTP clients, serialization code, or error handling layers. Spring AI handles communication with underlying AI services, letting us focus on delivering user-facing features. For production-grade stability, incorporate retry patterns and circuit breakers for<a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/resilience4j-circuit-breaker-retry-bulkhead-spring-boot\"> handling failures in AI workflows<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>As the landscape of generative AI evolves rapidly, the tools we use to integrate with it must be just as agile. Big Spring AI offers a powerful abstraction that brings the strengths of the Spring ecosystem&#8217;s modularity, configurability, and developer productivity to the world of large language models.<\/p>\n\n\n\n<p>Even with just a few classes and configuration files, you get a fully functional AI-backed API that\u2019s modular, extensible, and production-ready.<\/p>\n\n\n\n<p>But this is only the beginning. Spring AI is actively evolving to support features like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Streaming responses for real-time interactivity<\/li>\n\n\n\n<li>Structured output parsing<\/li>\n\n\n\n<li>Prompt templating<\/li>\n\n\n\n<li>Retrieval-augmented generation (RAG)<\/li>\n\n\n\n<li>Tool-using agents and orchestration<\/li>\n<\/ul>\n\n\n\n<p>Whether you&#8217;re building an intelligent chatbot, a document summarizer, or integrating AI into business workflows, Spring AI lets you focus on what your app should do, not how to wire up every model-specific detail.<\/p>\n\n\n\n<p>If you&#8217;re a Java or Spring developer and you&#8217;re starting to explore AI in your projects, Spring AI is one of the fastest and cleanest ways to get started. Try this POC structure, plug in your preferred AI provider, and build something useful fast.<\/p>\n\n\n\n<p>You can integrate these components into<a href=\"https:\/\/mobisoftinfotech.com\/services\/custom-software-development-houston?utm_source=blog&amp;utm_campaign=spring-ai-llm-integration-spring-boot\"> custom enterprise software development<\/a> projects tailored to your specific business needs.<\/p>\n\n\n\n<p>You can find the complete source code for the POC on <a href=\"https:\/\/github.com\/mobisoftinfotech\/spring-ai-tutorial\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub <\/a>here:<\/p>\n\n\n\n<p>Clone it, experiment with prompts, switch providers, and see how easily you can implement a Spring AI tutorial with Spring Boot AI integration in your Java applications.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mobisoftinfotech.com\/contact-us?utm_source=blog_cta&amp;utm_campaign=spring-ai-llm-integration-spring-boot\"><noscript><img decoding=\"async\" width=\"855\" height=\"363\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/build-map-app-react-native.png\" alt=\"Tailored Spring Boot applications with AI and LLM integration\" class=\"wp-image-41425\" title=\"Build Custom AI Solutions\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"363\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20363%22%3E%3C%2Fsvg%3E\" alt=\"Tailored Spring Boot applications with AI and LLM integration\" class=\"wp-image-41425 lazyload\" title=\"Build Custom AI Solutions\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/build-map-app-react-native.png\"><\/a><\/figure>\n\n\n<div class=\"modern-author-card\">\n    <div class=\"author-card-content\">\n        <div class=\"author-info-section\">\n            <div class=\"author-avatar\">\n                <noscript><img decoding=\"async\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/author-dattatray-dhawale.jpg\" alt=\"Dattatraya Dhawale\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"Dattatraya Dhawale\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/author-dattatray-dhawale.jpg\" class=\" lazyload\">\n            <\/div>\n            <div class=\"author-details\">\n                <h3 class=\"author-name\">Dattatraya Dhawale<\/h3>\n                <p class=\"author-title\">Java Developer<\/p>\n                <a href=\"javascript:void(0);\" class=\"read-more-link read-more-btn\" onclick=\"toggleAuthorBio(this); return false;\">Read more <noscript><img decoding=\"async\" src=\"\/assets\/images\/blog\/Vector.png\" alt=\"expand\" class=\"read-more-arrow down-arrow\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"expand\" class=\"read-more-arrow down-arrow lazyload\" data-src=\"\/assets\/images\/blog\/Vector.png\"><\/a>\n                <div class=\"author-bio-expanded\">\n                    <p>Dattatraya Dhawale brings over 8 years of industry experience as a Java developer, focused on enterprise-grade backend development. At <a href=\"https:\/\/mobisoftinfotech.com?utm_source=blog&amp;utm_medium=internal_link&amp;utm_campaign=resilience4j-circuit-breaker_blog&amp;utm_content=home-page\">Mobisoft Infotech<\/a>, he builds robust, high-performing applications with a strong emphasis on scalability and seamless connectivity to third-party services. Driven by a pragmatic mindset and hands-on approach, Dattatraya also brings prior experience in Android development, adding versatility to his backend expertise.<\/p>\n                    <div class=\"author-social-links\"><div class=\"social-icon\"><a href=\"https:\/\/www.linkedin.com\/in\/dattatraya-dhawale-493689142\" target=\"_blank\" rel=\"nofollow noopener\"><i class=\"icon-sprite linkedin\"><\/i><\/a><\/div><\/div>\n                    <a href=\"javascript:void(0);\" class=\"read-more-link read-less-btn\" onclick=\"toggleAuthorBio(this); return false;\" style=\"display: none;\">Read less <noscript><img decoding=\"async\" src=\"\/assets\/images\/blog\/Vector.png\" alt=\"collapse\" class=\"read-more-arrow up-arrow\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"collapse\" class=\"read-more-arrow up-arrow lazyload\" data-src=\"\/assets\/images\/blog\/Vector.png\"><\/a>\n                <\/div>\n            <\/div>\n        <\/div>\n        <div class=\"share-section\">\n            <span class=\"share-label\">Share Article<\/span>\n            <div class=\"social-share-buttons\">\n                <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fmobisoftinfotech.com%2Fresources%2Fblog%2Fai-development%2Fspring-ai-llm-integration-spring-boot\" target=\"_blank\" class=\"share-btn facebook-share\"><i class=\"fa fa-facebook-f\"><\/i><\/a>\n                <a href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=https%3A%2F%2Fmobisoftinfotech.com%2Fresources%2Fblog%2Fai-development%2Fspring-ai-llm-integration-spring-boot\" target=\"_blank\" class=\"share-btn linkedin-share\"><i class=\"fa fa-linkedin\"><\/i><\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n\n<style>\n.wp-block-table .has-fixed-layout td, .wp-block-table .has-fixed-layout th{font-weight: 500;}\n.hljs-title, .hljs-section, .hljs-keyword, .hljs-attribute, .hljs-selector-tag, .hljs-meta-keyword, .hljs-doctag, .hljs-name{    font-weight: normal;}\n.post-details-title{font-size:42px}\nh6.wp-block-heading {\n    line-height: 2;\n}\n.social-icon{\ntext-align:left;\n}\nspan.bullet{\nposition: relative;\npadding-left:20px;\n}\n.ta-l,.post-content .auth-name{\ntext-align:left;\n}\nspan.bullet:before {\n    content: '';\n    width: 9px;\n    height: 9px;\n    background-color: #0d265c;\n    border-radius: 50%;\n    position: absolute;\n    left: 0px;\n    top: 3px;\n}\n.post-content p{\n    margin: 20px 0 20px;\n}\n.image-container{\n    margin: 0 auto;\n    width: 50%;\n}\nh5.wp-block-heading{\nfont-size:18px;\nposition: relative;\n\n}\nh4.wp-block-heading{\nfont-size:20px;\nposition: relative;\n\n}\nh3.wp-block-heading{\nfont-size:22px;\nposition: relative;\n\n}\n.para-after-small-heading {\n    margin-left: 40px !important;\n}\nh4.wp-block-heading.h4-list, h5.wp-block-heading.h5-list{ padding-left: 20px;}\nh3.wp-block-heading.h3-list {\n    position: relative;\nfont-size:20px;\n    margin-left: 20px;\n    padding-left: 20px;\n}\n\nh3.wp-block-heading.h3-list:before, h4.wp-block-heading.h4-list:before, h5.wp-block-heading.h5-list:before {\n    position: absolute;\n    content: '';\n    background: #0d265c;\n    height: 9px;\n    width: 9px;\n    left: 0;\n    border-radius: 50px;\n    top: 8px;\n}\n@media only screen and (max-width: 991px) {\nul.wp-block-list.step-9-ul {\n    margin-left: 0px;\n}\n.step-9-h4{padding-left:0px;}\n    .post-content li {\n       padding-left: 25px;\n    }\n    .post-content li:before {\n        content: '';\n         width: 9px;\n        height: 9px;\n        background-color: #0d265c;\n        border-radius: 50%;\n        position: absolute;\n        left: 0px;\n        top: 7px;\n    }\n}\n@media (max-width:767px) {\n  .image-container{\n    width:90% !important;\n  }\n  \n}\n<\/style>\n<script type=\"application\/ld+json\">\n{\n\"@context\": \"https:\/\/schema.org\",\n\"@type\": \"Article\",\n\"mainEntityOfPage\": {\n\"@type\": \"WebPage\",\n\"@id\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\"\n},\n\"headline\": \"Mastering Spring AI: Easily Add LLM Smarts to Your Spring Boot Applications\",\n\"description\": \"Build smart Spring Boot apps with Spring AI! Learn to integrate LLMs, use prompt engineering, RAG pipelines, embeddings, and vector stores with ease.\",\n\"image\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot\",\n\"author\": {\n\"@type\": \"Person\",\n\"name\": \"Dattatraya Dhawale\",\n\"description\": \"Dattatraya Dhawale brings over 8 years of industry experience as a Java developer, focused on enterprise-grade backend development. At Mobisoft Infotech, he builds robust, high-performing applications with a strong emphasis on scalability and seamless connectivity to third-party services. Driven by a pragmatic mindset and hands-on approach, Dattatraya also brings prior experience in Android development, adding versatility to his backend expertise.\"\n},\n\"publisher\": {\n\"@type\": \"Organization\",\n\"name\": \"Mobisoft Infotech\",\n\"logo\": {\n\"@type\": \"ImageObject\",\n\"url\": \"https:\/\/mobisoftinfotech.com\/assets\/images\/mshomepage\/MI_Logo-white.svg\",\n\"width\": 600,\n\"height\": 600\n}\n},\n\"datePublished\": \"2025-08-1\",\n\"dateModified\": \"2025-08-1\"\n}\n<\/script>\n\n <script type=\"application\/ld+json\">\n{\n    \"@context\": \"https:\/\/schema.org\",\n    \"@type\": \"LocalBusiness\",\n    \"name\": \"Mobisoft Infotech\",\n    \"url\": \"https:\/\/mobisoftinfotech.com\",\n    \"logo\": \"https:\/\/mobisoftinfotech.com\/assets\/images\/mshomepage\/MI_Logo-white.svg\",\n    \"description\": \"Mobisoft Infotech specializes in custom software development and digital solutions.\",\n    \"address\": {\n        \"@type\": \"PostalAddress\",\n        \"streetAddress\": \"5718 Westheimer Rd Suite 1000\",\n        \"addressLocality\": \"Houston\",\n        \"addressRegion\": \"TX\",\n        \"postalCode\": \"77057\",\n        \"addressCountry\": \"USA\"\n    },\n    \"contactPoint\": [{\n        \"@type\": \"ContactPoint\",\n        \"telephone\": \"+1-855-572-2777\",\n        \"contactType\": \"Customer Service\",\n        \"areaServed\": [\"USA\", \"Worldwide\"],\n        \"availableLanguage\": [\"English\"]\n    }],\n    \"sameAs\": [\n        \"https:\/\/www.facebook.com\/pages\/Mobisoft-Infotech\/131035500270720\",\n        \"https:\/\/x.com\/MobisoftInfo\",\n        \"https:\/\/www.linkedin.com\/company\/mobisoft-infotech\",\n        \"https:\/\/in.pinterest.com\/mobisoftinfotech\/\",\n        \"https:\/\/www.instagram.com\/mobisoftinfotech\/\",\n        \"https:\/\/github.com\/MobisoftInfotech\",\n        \"https:\/\/www.behance.net\/MobisoftInfotech\",\n        \"https:\/\/www.youtube.com\/@MobisoftinfotechHouston\"\n    ]\n}\n<\/script>\n<script type=\"application\/ld+json\">\n    [\n    {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\",\n            \"name\": \"Mastering Spring AI: Easily Add LLM Smarts to Your Spring Boot Applications\",\n            \"caption\": \"Cover image showcasing Spring AI with LLM integration in enterprise apps\",\n            \"description\": \"Blog header image highlighting the concept of integrating large language models with Spring Boot using Spring AI in real-world enterprise applications.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/private-llm-spring-ai-integration.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\",\n            \"name\": \"Custom LLM Integration Solutions\",\n            \"caption\": \"Unlock enterprise-grade AI capabilities using Spring Boot and Spring AI\",\n            \"description\": \"A bold call-to-action image emphasizing full ownership and control with private LLM deployment in Spring Boot applications using Spring AI.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/private-llm-spring-ai-integration.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-boot-custom-ai-development.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\",\n            \"name\": \"Build Custom AI Solutions\",\n            \"caption\": \"Let\u2019s transform your next big idea into an AI-powered application\",\n            \"description\": \"Promotional image encouraging businesses to develop custom Spring Boot applications integrated with Spring AI and LLM capabilities.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-boot-custom-ai-development.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-prompt-engineering-workflow.jpg\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\",\n            \"name\": \"Prompt Engineering with Spring AI\",\n            \"caption\": \"Visual representation of prompt design and variable injection\",\n            \"description\": \"Diagram demonstrating how prompt templates, dynamic injection, and output parsing are managed using Spring AI for clean AI integration.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-prompt-engineering-workflow.jpg\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-openai-integration-code.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\",\n            \"name\": \"Spring AI OpenAI Code Integration\",\n            \"caption\": \"Code snippet showcasing how to connect OpenAI with Spring AI\",\n            \"description\": \"A screenshot of working Spring Boot code that demonstrates how developers can implement OpenAI integration using the Spring AI library.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-openai-integration-code.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-architecture-llm-java.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\",\n            \"name\": \"Spring AI Architecture for Java LLM Integration\",\n            \"caption\": \"Modular architecture showing Spring AI + LLM models like OpenAI\/Gemini\",\n            \"description\": \"Technical diagram outlining the architecture of Spring AI components in a Spring Boot app using different LLM providers such as OpenAI or Vertex AI Gemini.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-architecture-llm-java.png\"\n        }\n        ]\n    <\/script>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The Rise of AI APIs Over the past few years, AI has rapidly transitioned from research labs to real-world applications. Thanks to AI APIs from providers like OpenAI, Google Gemini, Anthropic Claude, and others, developers can now access powerful large language models (LLMs) with just a few lines of code, making Spring Boot AI [&hellip;]<\/p>\n","protected":false},"author":119,"featured_media":41420,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[5051],"tags":[6927,6935,6928,6937,6936,6934,6938,6933,6932,6940,6930,6939,6931,6942,6941,6929],"class_list":["post-41396","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-development","tag-big-spring-ai","tag-how-to-integrate-llm-in-spring-boot","tag-spring-ai","tag-spring-ai-embedding-configuration-tutorial","tag-spring-ai-java-llm-integration","tag-spring-ai-llm","tag-spring-ai-llm-integration","tag-spring-ai-local-llm","tag-spring-ai-openai-integration","tag-spring-ai-prompt-design-patterns","tag-spring-ai-prompt-engineering","tag-spring-ai-rag-pipeline","tag-spring-ai-tutorial","tag-spring-ai-vector-store-rag-example","tag-spring-ai-with-openai-llm","tag-spring-boot-ai"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Master Spring AI: LLM Integration for Spring Boot Devs<\/title>\n<meta name=\"description\" content=\"Build smart Spring Boot apps with Spring AI! Learn to integrate LLMs, use prompt engineering, RAG pipelines, embeddings, and vector stores with ease.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Master Spring AI: LLM Integration for Spring Boot Devs\" \/>\n<meta property=\"og:description\" content=\"Build smart Spring Boot apps with Spring AI! Learn to integrate LLMs, use prompt engineering, RAG pipelines, embeddings, and vector stores with ease.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\" \/>\n<meta property=\"og:site_name\" content=\"Mobisoft Infotech\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-01T12:16:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-15T09:50:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/Blog-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"525\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Dattatray Dhawale\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dattatray Dhawale\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#article\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\"},\"author\":{\"name\":\"Dattatray Dhawale\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/038e7f28f9722a8f9c662da7c1562bcc\"},\"headline\":\"Mastering Spring AI: Easily Add LLM Smarts to Your Spring Boot Applications\",\"datePublished\":\"2025-08-01T12:16:58+00:00\",\"dateModified\":\"2025-10-15T09:50:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\"},\"wordCount\":3589,\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot.png\",\"keywords\":[\"big spring ai\",\"how to integrate llm in spring boot\",\"spring ai\",\"spring ai embedding configuration tutorial\",\"spring ai java llm integration\",\"spring ai llm\",\"spring ai llm integration\",\"spring ai local llm\",\"spring ai openai integration\",\"spring ai prompt design patterns\",\"spring ai prompt engineering\",\"spring ai rag pipeline\",\"spring ai tutorial\",\"spring ai vector store rag example\",\"spring ai with openai llm\",\"spring boot ai\"],\"articleSection\":[\"AI Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\",\"name\":\"Master Spring AI: LLM Integration for Spring Boot Devs\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#primaryimage\"},\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot.png\",\"datePublished\":\"2025-08-01T12:16:58+00:00\",\"dateModified\":\"2025-10-15T09:50:33+00:00\",\"author\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/038e7f28f9722a8f9c662da7c1562bcc\"},\"description\":\"Build smart Spring Boot apps with Spring AI! Learn to integrate LLMs, use prompt engineering, RAG pipelines, embeddings, and vector stores with ease.\",\"breadcrumb\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#primaryimage\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot.png\",\"contentUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot.png\",\"width\":855,\"height\":363,\"caption\":\"Spring AI integration in Spring Boot applications\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mobisoftinfotech.com\/resources\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mastering Spring AI: Easily Add LLM Smarts to Your Spring Boot Applications\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/\",\"name\":\"Mobisoft Infotech\",\"description\":\"Discover Mobility\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/038e7f28f9722a8f9c662da7c1562bcc\",\"name\":\"Dattatray Dhawale\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/6c870d9e909d81d7f973503a08ca66afd65dcb3882140c657957c7653d4c7223?s=96&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6c870d9e909d81d7f973503a08ca66afd65dcb3882140c657957c7653d4c7223?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6c870d9e909d81d7f973503a08ca66afd65dcb3882140c657957c7653d4c7223?s=96&r=g\",\"caption\":\"Dattatray Dhawale\"},\"sameAs\":[\"https:\/\/mobisoftinfotech.com\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Master Spring AI: LLM Integration for Spring Boot Devs","description":"Build smart Spring Boot apps with Spring AI! Learn to integrate LLMs, use prompt engineering, RAG pipelines, embeddings, and vector stores with ease.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot","og_locale":"en_US","og_type":"article","og_title":"Master Spring AI: LLM Integration for Spring Boot Devs","og_description":"Build smart Spring Boot apps with Spring AI! Learn to integrate LLMs, use prompt engineering, RAG pipelines, embeddings, and vector stores with ease.","og_url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot","og_site_name":"Mobisoft Infotech","article_published_time":"2025-08-01T12:16:58+00:00","article_modified_time":"2025-10-15T09:50:33+00:00","og_image":[{"width":1000,"height":525,"url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/Blog-og.png","type":"image\/png"}],"author":"Dattatray Dhawale","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dattatray Dhawale","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#article","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot"},"author":{"name":"Dattatray Dhawale","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/038e7f28f9722a8f9c662da7c1562bcc"},"headline":"Mastering Spring AI: Easily Add LLM Smarts to Your Spring Boot Applications","datePublished":"2025-08-01T12:16:58+00:00","dateModified":"2025-10-15T09:50:33+00:00","mainEntityOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot"},"wordCount":3589,"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#primaryimage"},"thumbnailUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot.png","keywords":["big spring ai","how to integrate llm in spring boot","spring ai","spring ai embedding configuration tutorial","spring ai java llm integration","spring ai llm","spring ai llm integration","spring ai local llm","spring ai openai integration","spring ai prompt design patterns","spring ai prompt engineering","spring ai rag pipeline","spring ai tutorial","spring ai vector store rag example","spring ai with openai llm","spring boot ai"],"articleSection":["AI Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot","url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot","name":"Master Spring AI: LLM Integration for Spring Boot Devs","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#website"},"primaryImageOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#primaryimage"},"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#primaryimage"},"thumbnailUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot.png","datePublished":"2025-08-01T12:16:58+00:00","dateModified":"2025-10-15T09:50:33+00:00","author":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/038e7f28f9722a8f9c662da7c1562bcc"},"description":"Build smart Spring Boot apps with Spring AI! Learn to integrate LLMs, use prompt engineering, RAG pipelines, embeddings, and vector stores with ease.","breadcrumb":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#primaryimage","url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot.png","contentUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/08\/spring-ai-llm-integration-spring-boot.png","width":855,"height":363,"caption":"Spring AI integration in Spring Boot applications"},{"@type":"BreadcrumbList","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/ai-development\/spring-ai-llm-integration-spring-boot#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mobisoftinfotech.com\/resources\/"},{"@type":"ListItem","position":2,"name":"Mastering Spring AI: Easily Add LLM Smarts to Your Spring Boot Applications"}]},{"@type":"WebSite","@id":"https:\/\/mobisoftinfotech.com\/resources\/#website","url":"https:\/\/mobisoftinfotech.com\/resources\/","name":"Mobisoft Infotech","description":"Discover Mobility","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/038e7f28f9722a8f9c662da7c1562bcc","name":"Dattatray Dhawale","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/6c870d9e909d81d7f973503a08ca66afd65dcb3882140c657957c7653d4c7223?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6c870d9e909d81d7f973503a08ca66afd65dcb3882140c657957c7653d4c7223?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6c870d9e909d81d7f973503a08ca66afd65dcb3882140c657957c7653d4c7223?s=96&r=g","caption":"Dattatray Dhawale"},"sameAs":["https:\/\/mobisoftinfotech.com\/"]}]}},"_links":{"self":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/41396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/comments?post=41396"}],"version-history":[{"count":40,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/41396\/revisions"}],"predecessor-version":[{"id":44146,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/41396\/revisions\/44146"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media\/41420"}],"wp:attachment":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media?parent=41396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/categories?post=41396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/tags?post=41396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}