fix(spring-ai): order SpringAI auto-configuration after Spring AI mod… - #1505
Open
Lubaoshuai wants to merge 1 commit into
Open
fix(spring-ai): order SpringAI auto-configuration after Spring AI mod…#1505Lubaoshuai wants to merge 1 commit into
Lubaoshuai wants to merge 1 commit into
Conversation
…el auto-configurations The @ConditionalOnBean guards on the SpringAI bean methods were evaluated before the Spring AI provider auto-configurations had run: with no ordering declared, alphabetical sorting puts this configuration (com.google.adk...) ahead of org.springframework.ai.model.*.autoconfigure .*AutoConfiguration in real applications, so every condition misses and the SpringAI/SpringAIEmbedding beans are silently never created (google#1501). Declare afterName over the Spring AI 2.x chat and embedding model auto-configurations (class names verified against each module's AutoConfiguration.imports at v2.0.1). String-based afterName is required because this module only compiles against spring-ai-model, and unknown names are ignored, so versions without a listed configuration are unaffected. Add an ordering regression test that drives the real OpenAI chat and embedding auto-configurations through AutoConfigurations (same sorter as a real application): it fails while the ordering is missing and passes with it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1501
Root cause
SpringAIAutoConfigurationguards its@Beanmethods with@ConditionalOnBean(ChatModel/StreamingChatModel/EmbeddingModel), but declared no ordering relative to the Spring AI model auto-configurations that register those beans.@ConditionalOnBeanis evaluated when the configuration is processed, and in a real application the auto-configurations are otherwise sorted alphabetically, which putscom.google.adk.models.springai.autoconfigure.SpringAIAutoConfigurationbeforeorg.springframework.ai.model.*.autoconfigure.*AutoConfiguration— every condition misses, and allSpringAI/SpringAIEmbeddingbeans are silently skipped (thespringAIEmbeddingfailure being fully silent, as noted in the issue).Since this module intentionally compiles only against
spring-ai-model(no provider modules on the compile classpath), the class-basedafterattribute is not usable; the string-basedafterNameattribute exists exactly for this case, and unknown class names are ignored, so versions that lack a listed configuration are unaffected. This mirrors the approach Spring AI 1.x's ownChatClientAutoConfigurationused for the identical@ConditionalOnBean(ChatModel)situation.The list covers the chat/embedding auto-configurations that exist in Spring AI 2.0.x, verified against each module's
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.importsat v2.0.1:Testing
New
SpringAIAutoConfigurationOrderingTestbuilds anApplicationContextRunnerwithAutoConfigurations.of(SpringAIAutoConfiguration.class, OpenAiChatAutoConfiguration.class, OpenAiEmbeddingAutoConfiguration.class, ToolCallingAutoConfiguration.class).AutoConfigurationsapplies the sameAutoConfigurationSorteras a real application, so:com.google.adk...configuration is processed beforeorg.springframework.ai...and noSpringAIbean exists),SpringAIandSpringAIEmbeddingbeans are created.spring-ai-autoconfigure-model-openaiandspring-ai-autoconfigure-model-toolare added as test-scoped dependencies to make the real provider configurations available to the runner.Module test run: 2/2 passing; the ordering test was also verified to fail when the
afterNamedeclaration is reverted (test-first verification).