Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Provides integration patterns for LangChain4j with Spring Boot. Configures AI model beans, sets up chat memory with Spring context, integrates RAG pipelines with Spring Data, and handles auto-configuration, dependency injection, and Spring ecosystem integration. Use when embedding LangChain4j into Spring Boot applications, building Java LLM applications with @Bean configuration, or setting up Spring AI patterns.
.claude/skills/giuseppe-trisciuoglio-langchain4j-spring-boot-integration/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 85% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 49% | 0% |
| case-22 | ✗→✓ | ▲ Improved | 7% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 40% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 75% | 0% |
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.
Use this skill when:
@Bean annotationsLangChain4j 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.
xml<!-- 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>
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:
yamllangchain4j: open-ai: chat-model: api-key: ${OPENAI_API_KEY} model-name: gpt-4o-mini temperature: 0.7 timeout: 60s max-tokens: 1000
javaimport 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); }
java@SpringBootApplication @ComponentScan(basePackages = { "com.yourcompany", "dev.langchain4j.service.spring" }) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
java@Service public class CustomerService { private final CustomerSupportAssistant assistant; public CustomerService(CustomerSupportAssistant assistant) { this.assistant = assistant; } public String processCustomerQuery(String query) { return assistant.handleInquiry(query); } }
After setup, verify the configuration:
LangChain4jSpringBootAutoConfiguration activationCustomerSupportAssistant in Spring contextassistant.handleInquiry("test") and verify a response is returnedProperty-Based Configuration: Configure AI models through application.properties for different providers.
Manual Bean Configuration: For advanced configurations, define beans manually:
java@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:
java@AiService(wiringMode = WiringMode.EXPLICIT) interface MultiProviderAssistant { @AiServiceAnnotation ChatModel openAiModel; @AiServiceAnnotation ChatModel azureModel; }
Basic AI Service: Create interfaces with @AiService annotation and define methods with message templates.
Streaming AI Service: Implement streaming responses using Project Reactor:
java@AiService public interface StreamingAssistant { @SystemMessage("You are a helpful assistant.") Flux<String> chatStream(String message); }
Chat Memory: Set up conversation memory with Spring context:
java@AiService public interface ConversationalAssistant { @SystemMessage("You are a helpful assistant with memory.") String chat(@MemoryId String userId, String message); }
Embedding Stores: Configure embedding stores for RAG pipelines with Spring Data:
java@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.
Spring Component Tools: Define tools as Spring components:
java@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); }
java@AiService public interface ChatAssistant { @SystemMessage("You are a helpful assistant.") String chat(String message); }
java@AiService public interface ConversationalAssistant { @SystemMessage("You are a helpful assistant with memory of conversations.") String chat(@MemoryId String userId, String message); }
java@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.
For detailed API references and advanced configurations:
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 8,769 | 6,008 | -31% | 1 | 1 | 0% | 1,764 | 3,266 | +85% | 0 | 0 | — |
case-02 | pass→pass | 14,547 | 14,885 | +2% | 1 | 1 | 0% | 2,818 | 3,943 | +40% | 0 | 0 | — |
case-03 | pass→pass | 11,460 | 9,385 | -18% | 1 | 1 | 0% | 2,277 | 3,974 | +75% | 0 | 0 | — |
case-04 | pass→pass | 11,204 | 6,814 | -39% | 1 | 1 | 0% | 2,154 | 3,299 | +53% | 0 | 0 | — |
case-05 | pass→pass | 10,326 | 8,074 | -22% | 1 | 1 | 0% | 2,037 | 3,681 | +81% | 0 | 0 | — |
case-06 | pass→pass | 14,020 | 3,714 | -74% | 1 | 1 | 0% | 2,526 | 2,606 | +3% | 0 | 0 | — |
case-07 | pass→pass | 5,390 | 3,789 | -30% | 1 | 1 | 0% | 1,015 | 2,458 | +142% | 0 | 0 | — |
case-08 | fail→pass | 11,677 | 6,805 | -42% | 1 | 1 | 0% | 2,180 | 3,254 | +49% | 0 | 0 | — |
case-09 | pass→pass | 10,008 | 5,744 | -43% | 1 | 1 | 0% | 1,620 | 2,974 | +84% | 0 | 0 | — |
case-10 | pass→pass | 5,940 | 3,698 | -38% | 1 | 1 | 0% | 959 | 2,667 | +178% | 0 | 0 | — |
case-11 | pass→pass | 5,476 | 4,466 | -18% | 1 | 1 | 0% | 1,067 | 2,847 | +167% | 0 | 0 | — |
case-12 | pass→pass | 9,332 | 3,779 | -60% | 1 | 1 | 0% | 1,537 | 2,566 | +67% | 0 | 0 | — |
case-13 | pass→pass | 5,051 | 3,762 | -26% | 1 | 1 | 0% | 822 | 2,573 | +213% | 0 | 0 | — |
case-14 | pass→pass | 5,428 | 3,173 | -42% | 1 | 1 | 0% | 932 | 2,617 | +181% | 0 | 0 | — |
case-15 | pass→pass | 7,773 | 4,614 | -41% | 1 | 1 | 0% | 1,572 | 2,857 | +82% | 0 | 0 | — |
case-16 | pass→pass | 9,556 | 5,043 | -47% | 1 | 1 | 0% | 1,736 | 2,942 | +69% | 0 | 0 | — |
case-17 | pass→pass | 3,625 | 2,622 | -28% | 1 | 1 | 0% | 601 | 2,489 | +314% | 0 | 0 | — |
case-18 | pass→pass | 11,302 | 9,568 | -15% | 1 | 1 | 0% | 2,004 | 3,745 | +87% | 0 | 0 | — |
case-19 | pass→pass | 5,886 | 3,537 | -40% | 1 | 1 | 0% | 956 | 2,679 | +180% | 0 | 0 | — |
case-20 | pass→pass | 3,501 | 3,945 | +13% | 1 | 1 | 0% | 566 | 2,636 | +366% | 0 | 0 | — |
case-21 | pass→pass | 3,414 | 2,302 | -33% | 1 | 1 | 0% | 566 | 2,340 | +313% | 0 | 0 | — |
case-22 | fail→pass | 11,018 | 1,878 | -83% | 1 | 1 | 0% | 2,067 | 2,218 | +7% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +14 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.