r/JavaProgramming • • 13m ago

You don't need Spring AI to build AI-powered Java applications

With all the recent attention around Spring AI, I think it's worth highlighting LangChain4j as a framework-independent alternative.

LangChain4j provides many of the same capabilities: chat, structured output, tool calling, RAG, conversation memory, streaming and MCP. You can use it with virtually any Java framework or just plain Java.

I recently put together a small integration example using CoilBase and Jex. No dedicated integration module, DI container or Spring dependencies. Just ordinary Java services and constructor wiring.

The example verifies chat, structured output mapped to a Java record, automatic tool calling and HTTP application lifecycle. It uses a mock model, so no API keys or paid LLM calls are needed to reproduce the tests.

I also included a table mapping common Spring AI capabilities to LangChain4j.

Integration guide:
https://github.com/PVRLabs/coilbase/blob/main/docs/langchain4j.md

Working example and tests:
https://github.com/PVRLabs/experiments/tree/main/java/coilbase/langchain4j-recipe

The same approach can be adapted to other Java frameworks.

Anyone here using LangChain4j outside the Spring ecosystem? How has your experience been?

1 Upvotes

0 comments sorted by