Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
giuseppe-trisciuoglio avatar

Langchain4j Spring Boot Integration

  • 1.6k installs
  • 311 repo stars
  • Updated June 22, 2026
  • giuseppe-trisciuoglio/developer-kit

How to integrate LangChain4j into Spring Boot applications using declarative AI Services, auto-configuration, and Spring dependency injection for production-ready AI microservices.

About

LangChain4j Spring Boot integration enables developers to embed AI capabilities into Spring applications through declarative AI Services, auto-configuration, and Spring dependency injection. Developers use this when building AI-powered microservices, configuring multiple AI providers (OpenAI, Azure, Ollama, Anthropic), and implementing RAG pipelines with Spring Data. Key workflows include defining AI services via @AiService interfaces, configuring models through application properties, setting up chat memory with Spring context, and integrating tools as Spring components. The skill handles bean registration, property-based configuration across providers, streaming responses via Project Reactor, and embedding store integration for knowledge augmentation.

  • Declarative AI Services using @AiService interfaces with message templates and Spring dependency injection
  • Auto-configuration and property-based setup for OpenAI, Azure, Ollama, and Anthropic models without manual bean wiring
  • Chat memory with Spring context management via @MemoryId for multi-user conversational assistants
  • RAG pipeline integration with embedding stores (PgVector), document splitting, and content retrieval
  • Spring component tools using @Tool annotations and streaming responses with Project Reactor Flux

Langchain4j Spring Boot Integration by the numbers

  • 1,640 all-time installs (skills.sh)
  • +56 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Ranked #742 of 16,659 AI & Agent Building skills by installs in the Skillselion catalog
  • Security screen: HIGH risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
At a glance

langchain4j-spring-boot-integration capabilities & compatibility

Pay-per-token to AI providers (OpenAI, Azure, Anthropic); infrastructure costs for embedding store (PostgreSQL optional)

Capabilities
auto configuration of ai model beans via spring · declarative ai services with @aiservice and mess · multi provider ai model switching with property · chat memory management with spring context and @ · rag pipeline with embedding stores and spring da · tool integration via spring components and @tool · streaming responses using project reactor flux · dependency injection for ai services into other
Works with
openai · azure · anthropic · postgres
Use cases
api development · orchestration · code review · memory
Platforms
macOS · Windows · Linux · WSL
Runs
Remote server
Pricing
Free
From the docs

What langchain4j-spring-boot-integration says it does

Integrate LangChain4j with Spring Boot using declarative AI Services, auto-configuration, and Spring Boot starters.
README.md - Overview section
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill langchain4j-spring-boot-integration

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1.6k
repo stars311
Security audit3 / 3 scanners passed
Last updatedJune 22, 2026
Repositorygiuseppe-trisciuoglio/developer-kit

What it does

Integrate LangChain4j AI services into Spring Boot applications with declarative beans and auto-configuration.

Who is it for?

Java backend developers building Spring Boot microservices, enterprise AI integrations, multi-provider LLM deployments, conversational systems with memory, and RAG-augmented applications.

Skip if: Frontend frameworks, non-Spring Java applications, serverless functions, or use cases requiring non-declarative control over AI service lifecycle.

When should I use this skill?

Integrating LangChain4j into existing Spring Boot applications, configuring auto-configuration, defining AI Services with @AiService, setting up chat memory, implementing RAG with Spring Data, or building multi-provider

What you get

Developers can rapidly build AI-powered Spring Boot microservices with declarative AI Services, externalized configuration, memory management, tool integration, and RAG pipelines without managing low-level LangChain4j wi

  • Configured Spring Boot application with LangChain4j starter dependencies
  • Declarative @AiService interfaces with system and user message templates
  • Property-based configuration in application.properties/yaml for AI models

By the numbers

  • LangChain4j version 1.8.0 or later supports Spring Boot 3.0+ auto-configuration
  • Supports 4+ AI providers: OpenAI, Azure OpenAI, Ollama, Anthropic
  • Streaming via Project Reactor Flux for real-time responses

Files

SKILL.mdMarkdownGitHub ↗

LangChain4j Spring Boot Integration

Integrate LangChain4j with Spring Boot using declarative AI Services, auto-configuration, and Spring Boot starters. Configure AI model beans, set up chat memory, implement RAG pipelines with Spring Data, and build production-ready AI applications.

When to Use

Use this skill when:

  • Integrating LangChain4j into existing Spring Boot applications
  • Building AI-powered microservices with Spring Boot
  • Configuring AI model beans with @Bean annotations
  • Setting up auto-configuration for AI models and services
  • Creating declarative AI Services with Spring dependency injection
  • Implementing RAG systems with Spring Data integrations
  • Setting up chat memory with Spring context management
  • Configuring multiple AI providers (OpenAI, Azure, Ollama, Anthropic)
  • Building production-ready AI applications with Spring Boot

Overview

LangChain4j Spring Boot integration provides declarative AI Services through Spring Boot starters, enabling automatic configuration of AI components based on properties. Combine Spring dependency injection with LangChain4j's AI capabilities using interface-based definitions with annotations.

Instructions

1. Add Dependencies

<!-- Core LangChain4j Spring Boot Starter -->
<dependency>
    <groupId>dev.langchain4j</groupId>
    <artifactId>langchain4j-spring-boot-starter</artifactId>
    <version>1.8.0</version>
</dependency>

<!-- OpenAI Spring Boot Starter -->
<dependency>
    <groupId>dev.langchain4j</groupId>
    <artifactId>langchain4j-open-ai-spring-boot-starter</artifactId>
    <version>1.8.0</version>
</dependency>

2. Configure Application Properties

# application.properties
langchain4j.open-ai.chat-model.api-key=${OPENAI_API_KEY}
langchain4j.open-ai.chat-model.model-name=gpt-4o-mini
langchain4j.open-ai.chat-model.temperature=0.7
langchain4j.open-ai.chat-model.timeout=PT60S
langchain4j.open-ai.chat-model.max-tokens=1000

Or using YAML:

langchain4j:
  open-ai:
    chat-model:
      api-key: ${OPENAI_API_KEY}
      model-name: gpt-4o-mini
      temperature: 0.7
      timeout: 60s
      max-tokens: 1000

3. Create Declarative AI Service

import dev.langchain4j.service.spring.AiService;

@AiService
public interface CustomerSupportAssistant {

    @SystemMessage("You are a helpful customer support agent for TechCorp.")
    String handleInquiry(String customerMessage);

    @UserMessage("Translate to {{language}}: {{text}}")
    String translate(String text, String language);
}

4. Enable Component Scanning

@SpringBootApplication
@ComponentScan(basePackages = {
    "com.yourcompany",
    "dev.langchain4j.service.spring"
})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

5. Inject and Use the AI Service

@Service
public class CustomerService {

    private final CustomerSupportAssistant assistant;

    public CustomerService(CustomerSupportAssistant assistant) {
        this.assistant = assistant;
    }

    public String processCustomerQuery(String query) {
        return assistant.handleInquiry(query);
    }
}

6. Verify the Integration

After setup, verify the configuration: 1. Start the application and check logs for LangChain4jSpringBootAutoConfiguration activation 2. Confirm AI service beans are registered: look for CustomerSupportAssistant in Spring context 3. Test the service: invoke assistant.handleInquiry("test") and verify a response is returned

Configuration

Property-Based Configuration: Configure AI models through application.properties for different providers.

Manual Bean Configuration: For advanced configurations, define beans manually:

@Configuration
public class AiConfig {

    @Bean
    public ChatModel chatModel(@Value("${OPENAI_API_KEY}") String apiKey) {
        return OpenAiChatModel.builder()
            .apiKey(apiKey)
            .modelName("gpt-4o-mini")
            .temperature(0.7)
            .build();
    }
}

Multiple Providers: Use explicit wiring when configuring multiple AI providers:

@AiService(wiringMode = WiringMode.EXPLICIT)
interface MultiProviderAssistant {
    @AiServiceAnnotation
    ChatModel openAiModel;

    @AiServiceAnnotation
    ChatModel azureModel;
}

Declarative AI Services

Basic AI Service: Create interfaces with @AiService annotation and define methods with message templates.

Streaming AI Service: Implement streaming responses using Project Reactor:

@AiService
public interface StreamingAssistant {
    @SystemMessage("You are a helpful assistant.")
    Flux<String> chatStream(String message);
}

Chat Memory: Set up conversation memory with Spring context:

@AiService
public interface ConversationalAssistant {
    @SystemMessage("You are a helpful assistant with memory.")
    String chat(@MemoryId String userId, String message);
}

RAG Implementation

Embedding Stores: Configure embedding stores for RAG pipelines with Spring Data:

@Configuration
public class RagConfig {

    @Bean
    public EmbeddingStore<TextSegment> embeddingStore() {
        return PgVectorEmbeddingStore.builder()
            .host("localhost")
            .port(5432)
            .database("vectordb")
            .table("embeddings")
            .dimension(1536)
            .build();
    }

    @Bean
    public EmbeddingModel embeddingModel() {
        return OpenAiEmbeddingModel.withApiKey(System.getenv("OPENAI_API_KEY"));
    }
}

@AiService
public interface RagAssistant {
    String answer(@UserMessage("Question: {{question}}") String question);
}

Document Ingestion: Use ContentInjector and DocumentSplitter for processing documents. Content Retrieval: Configure EmbeddingStoreContentRetriever for knowledge augmentation.

Tool Integration

Spring Component Tools: Define tools as Spring components:

@Component
public class Calculator {
    @Tool("Calculate the sum of two numbers")
    public double add(double a, double b) {
        return a + b;
    }
}

@AiService
public interface MathAssistant {
    String solve(String problem);
}

Examples

Basic AI Service

@AiService
public interface ChatAssistant {
    @SystemMessage("You are a helpful assistant.")
    String chat(String message);
}

AI Service with Memory

@AiService
public interface ConversationalAssistant {
    @SystemMessage("You are a helpful assistant with memory of conversations.")
    String chat(@MemoryId String userId, String message);
}

AI Service with Tools

@Component
public class WeatherService {
    @Tool("Get weather for a city")
    public String getWeather(String city) {
        return "Sunny, 22°C in " + city;
    }
}

@AiService
public interface WeatherAssistant {
    String getWeatherForCity(String city);
}

For more examples (including RAG configurations, streaming assistants, and multi-provider setups), refer to references/examples.md.

Best Practices

  • Use Property-Based Configuration: External configuration over hardcoded values
  • Use Profiles: Separate configurations for development, testing, and production
  • Add Proper Logging: Debug AI service calls and monitor performance
  • Implement Retry Mechanisms: Handle transient failures with backoff strategies
  • Monitor Token Usage: Track token consumption and implement limits

References

For detailed API references and advanced configurations:

  • API Reference - Complete API documentation
  • Examples - Comprehensive implementation examples
  • Configuration Guide - Deep dive into configuration options

Constraints and Warnings

  • Store API keys securely using environment variables or secret management systems
  • AI model responses are non-deterministic; tests should account for variability
  • Rate limits may apply to AI providers; implement proper retry and backoff strategies
  • Memory providers store conversation history; implement cleanup for multi-user scenarios
  • Token costs accumulate quickly; monitor usage and implement token limits
  • Streaming responses require proper error handling for partial failures
  • Check provider-specific documentation for supported features
  • Use explicit wiring mode when multiple chat models are configured
  • Validate AI-generated outputs before use in production systems

Related skills

Forks & variants (1)

Langchain4j Spring Boot Integration has 1 known copy in the catalog totaling 21 installs. They canonicalize to this original listing.

How it compares

Choose langchain4j-spring-boot-integration over generic LLM skills when the stack is Java Spring Boot with LangChain4j property-based configuration.

FAQ

How do I configure multiple AI providers in one Spring Boot application?

Use explicit wiring mode (WiringMode.EXPLICIT) in @AiService annotation and define separate ChatModel beans for each provider (OpenAI, Azure, Ollama). Configure each via application.properties with provider-specific prefixes like langchain4j.open-ai and langchain4j.azure-open-ai.

How does Spring context handle chat memory for conversations?

Use @MemoryId annotation on parameters to scope conversation history per user or session. Spring manages memory lifecycle through ChatMemory beans configured in the AI service, automatically maintaining state across multiple calls.

What embedding store options are available for RAG?

LangChain4j Spring Boot supports PgVectorEmbeddingStore for PostgreSQL, with EmbeddingStore<TextSegment> interface for extensibility. Configure via bean definitions with host, port, database, table, and dimension parameters.

Is Langchain4j Spring Boot Integration safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.