Skip to main content

Spring Boot Integration

LangChain4j provides Spring Boot starters for popular integrations.

To use one of the Spring Boot starters, first import the corresponding dependency:


Then, you can configure model parameters in the file as follows:${OPENAI_API_KEY}

The complete list of supported properties can be found here.

In this case, an instance of OpenAiChatModel (an implementation of a ChatLanguageModel) will be automatically created, and you can autowire it where needed.

If you need an instance of a StreamingChatLanguageModel, use the streaming-chat-model instead of the chat-model properties:${OPENAI_API_KEY}

LangChain4j Spring Boot Starter

LangChain4j provides a Spring Boot starter for auto-configuring AI Services, RAG, Tools etc.

Assuming you have already imported one of the integrations starters (see above), import langchain4j-spring-boot-starter:


You can now define AI Service interface and annotate it with @AiService:

interface Assistant {

@SystemMessage("You are a polite assistant")
String chat(String userMessage);

Think of it as a standard Spring Boot @Service, but with AI capabilities.

When the application starts, LangChain4j starter will scan the classpath and find all interfaces annotated with @AiService. For each AI Service found, it will create an implementation of this interface using all LangChain4j components available in the application context and will register it as a bean, so you can auto-wire it where needed:

class AssistantController {

Assistant assistant;

public String chat(String message) {

More details here.

Supported Spring Boot Versions

Spring Boot 2 and 3 are supported.