AI / LangChain4j interview questions
How do you integrate LangChain4j with Spring Boot?
LangChain4j provides a dedicated Spring Boot starter (langchain4j-spring-boot-starter) that wires everything up through standard Spring Boot auto-configuration. You add the starter plus the provider-specific starter for your chosen LLM, drop configuration into application.properties, and Spring automatically creates the ChatLanguageModel, EmbeddingModel, and related beans that you can inject anywhere in the application.
<!-- pom.xml -->
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-spring-boot-starter</artifactId>
<version>0.32.0</version>
</dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai-spring-boot-starter</artifactId>
<version>0.32.0</version>
</dependency># application.properties
langchain4j.open-ai.chat-model.api-key=${OPENAI_API_KEY}
langchain4j.open-ai.chat-model.model-name=gpt-4o
langchain4j.open-ai.chat-model.temperature=0.7
langchain4j.open-ai.embedding-model.api-key=${OPENAI_API_KEY}For AI Services specifically, Spring Boot integration uses the @AiService annotation (or you declare a @Bean manually). LangChain4j detects annotated interfaces during component scan and creates Spring-managed proxy beans — meaning the AI service is injectable like any other Spring component:
@AiService
interface CustomerSupportAgent {
@SystemMessage("You are a helpful customer support agent.")
String chat(String userMessage);
}
@RestController
class SupportController {
private final CustomerSupportAgent agent;
SupportController(CustomerSupportAgent agent) { this.agent = agent; }
@PostMapping("/support")
String support(@RequestBody String message) {
return agent.chat(message);
}
}
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
