Spring / Spring AI interview questions
How does Spring AI integrate with Spring Boot auto-configuration?
Spring AI follows standard Spring Boot auto-configuration conventions, which means zero boilerplate for the common case. When you add a provider starter to your dependencies and supply the required properties, Spring Boot auto-configures the AI beans you need without any @Configuration classes on your part.
Each provider starter (e.g. spring-ai-openai-spring-boot-starter) ships a spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports file that registers its auto-configuration classes. Those classes use @ConditionalOnProperty and @ConditionalOnMissingBean guards so they activate only when needed and back off when you declare your own bean.
What gets auto-configured per provider:
- A
ChatModelbean (e.g.OpenAiChatModel). - An
EmbeddingModelbean if the provider supports embeddings. - A
ChatClient.Builderprototype bean that injects the auto-configuredChatModel. - Provider-specific
@ConfigurationPropertiesbindings (API keys, base URLs, default model names, timeouts).
Minimal application.properties for OpenAI:
spring.ai.openai.api-key=${OPENAI_API_KEY} spring.ai.openai.chat.options.model=gpt-4o spring.ai.openai.chat.options.temperature=0.7
If you need to customise the HTTP client, add observability, or wire a custom RetryTemplate, declare a @Bean of the required type and Spring Boot's @ConditionalOnMissingBean will skip the auto-configured default in favour of yours.
More Related questions...