LangChain4j and Spring AI: The Plumbing to make your Java Apps talk to LLMs LangChain4j and Spring AI bring LLM integration to Java, providing reusable components for managing conversation history, document splitting, embeddings, vector search, and function calling. Spring AI 2.0, released in June, auto-configures with Spring Boot, allowing developers to call an LLM in about six lines of code without a Python sidecar. The libraries enable structured data extraction, grounding answers in internal documentation, and triggering real code from model outputs. If you've heard about LangChain and assumed it was a Python thing, that's fair. It mostly was. LangChain became popular because building with an LLM turns out to involve a lot of repetitive plumbing. You need to manage conversation history, split documents into chunks, generate embeddings, search a vector store, wire up functions the model can call, and parse whatever comes back. None of that is hard, but writing it from scratch for every project gets old fast. LangChain packaged those pieces into reusable components, and the pattern caught on. The Java ecosystem has that now too, in two flavors. LangChain4j is a Java library built around the same idea, though it was written for Java from the ground up rather than ported over. Spring AI does the same job the Spring way, with auto-configuration and dependency injection, and it hit 2.0 this June. Both are production ready. Your existing Spring Boot service can call an LLM in about six lines, and you don't need a Python sidecar or a separate service to do it. The six lines aren't the interesting part, though. What matters is the distance between a chat endpoint that echoes text back and something you'd actually ship: getting typed objects instead of strings, grounding answers in your own documentation, and letting a model trigger real code in your app. That's what this post covers. We'll build up from hello-world to a service that answers questions about your internal docs and can call your APIs, one step at a time. I'll use Spring AI for the walkthrough since most of us are already in a Boot service, then show what the same thing looks like in LangChain4j so you can pick. I'm assuming you know Java and Spring Boot, and nothing about AI. No math, no theory, just the parts you need to build something. One idea first, because it makes everything else fall into place. An LLM is a stateless function.Text in, text out. It doesn't remember your last call, can't reach the internet, and knows nothing about your systems. Everything below is a workaround for that: The model never does anything. Your code does everything. The model produces text, and sometimes that text is a decision about what your code should do next. That one idea demystifies most of this space. Everything from here is plumbing around a stateless function, and plumbing is something we're already good at. If you want more background on how LLMs, RAG, and agents fit together before diving in, I wrote about that here: Spring AI 2.0 needs Spring Boot 4.0+ and Java 17+.