Run Local LLMs with Ollama and Spring AI A developer demonstrates how to run local large language models with Ollama and integrate them into a Spring Boot application using Spring AI, building an AI customer support assistant that keeps data on-premises. The tutorial covers installing Ollama, pulling models like llama3.2, and connecting Spring AI's ChatClient to the local Ollama API, while noting that local deployment does not automatically ensure security. In the previous parts, we connected Spring AI with cloud-based AI models. But there is one important question: What if you don't want to send your data to an external AI provider? What if you want to: This is where Ollama becomes very useful. In this article, we will learn how to run a local LLM using Ollama and connect it with Spring AI . We will build a simple real-world AI Customer Support Assistant using Java, Spring Boot, Spring AI, and Ollama. Our application will look like this: User | | HTTP Request v +---------------------+ | Spring Boot API | +---------------------+ | v +-------------+ | Spring AI | | ChatClient | +-------------+ | v +--------+ | Ollama | +--------+ | v Local LLM Llama/Qwen | v AI Response | v User The important part is that the LLM is running locally . There is no need to send every prompt to OpenAI, Anthropic, or another cloud provider. Ollama https://ollama.com/ makes it easy to run open-source LLMs locally. Instead of calling a remote API like: Spring Boot | v OpenAI API | v Cloud LLM we can run: Spring Boot | v Spring AI | v Ollama | v Local LLM Ollama can run models such as: The exact models available change over time, so always check the Ollama model library before choosing one. Imagine you are building an internal HR application. Employees may send questions such as: What is our maternity leave policy? or: What is the process for requesting annual leave? You may not want internal company information leaving your infrastructure. A local LLM can help: Employee | v Spring Boot | v RAG / Business Logic | v Ollama | v Local LLM This can provide a useful privacy boundary. However, remember: Running an LLM locally does not automatically make your application secure. You still need proper authentication, authorization, logging, data protection, network security, and prompt/data controls. First, install Ollama on your operating system. After installation, verify it: ollama --version If the command works, Ollama is installed. Now we need an LLM. For example: ollama pull llama3.2 Then run it: ollama run llama3.2 You can now talk to the model directly from your terminal. For example: Explain Java interfaces in simple English. The model will generate a response locally. At a high level, the architecture is: Your Application | v Ollama API | v Model Runtime | v Local Model | v Response Ollama exposes an API that applications can communicate with. Spring AI can communicate with this API for us. That means we don't have to manually build HTTP requests to the Ollama API. Let's create a Spring Boot application. You can use Spring Initializr or your preferred IDE. Basic project: local-ai-demo │ ├── src │ └── main │ ├── java │ │ └── com.example.localai │ │ └── LocalAiApplication.java │ │ │ └── resources │ └── application.yml │ └── pom.xml We need: Add the Spring AI Ollama starter to your pom.xml .