Spring AI 2.0
When upgrading to Spring AI 2.0, refer to the Upgrade Notes for newly introduced APIs, deprecated APIs, and breaking changes.
The io.arconia.rewrite.spring.ai2.UpgradeSpringAi_2_0 recipe automates most of the changes introduced in Spring AI 2.0. You can use it to update your project to the latest Spring AI 2.0.x release.
The recipe will:
-
Upgrade all
org.springframework.aidependencies to the 2.0.x release line. -
Rename Spring AI configuration properties to match the new property names (including flattening the
.options.infix on embedding, image, audio, moderation, and OCR keys, and renamingspring.ai.ollama.chat.think-optiontospring.ai.ollama.chat.think). -
Comment out properties removed in 2.0, including each provider’s
spring.ai.<provider>.chat.options.internal-tool-execution-enabled,spring.ai.google.genai.chat.options.tool-names,spring.ai.chat.client.tool-calling.stream-tool-call-responses, andspring.ai.chat.client.tool-search-advisor.stream-tool-call-responses. -
Pass
ChatOptions.Builder(rather than a builtChatOptions) toChatClient.options(…)andChatClient.Builder.defaultOptions(…). -
Rename the tool-registration methods
ChatClient.ChatClientRequestSpec.toolCallbacks(…)andChatClient.Builder.defaultToolCallbacks(…)totools(…)anddefaultTools(…), aligning with the new tool-calling API. -
Rename
ChatModel.getDefaultOptions()togetOptions(). -
Rename
JsonParser.getObjectMapper()toJsonParser.getJsonMapper(). -
Rename the
N(Integer)builder method ton(Integer)onImageOptionsBuilder,OpenAiChatOptions.Builder, andOpenAiImageOptions.Builderto align with Java naming conventions. -
Apply the dependency rename from
spring-ai-advisors-vector-storetospring-ai-vector-store-advisor. -
Update type references such as
PromptChatMemoryAdvisor→MessageChatMemoryAdvisor,OpensearchContainer→OpenSearchContainer, andChatClientCustomizer→ChatClientBuilderCustomizer. -
For Anthropic: relocate Anthropic types (
AnthropicCacheOptions,AnthropicCacheStrategy,AnthropicCacheTtl,CacheEligibilityResolver,CitationDocument→AnthropicCitationDocument) fromorg.springframework.ai.anthropic.apitoorg.springframework.ai.anthropic. Note that constructingAnthropicChatModelfrom anAnthropicApino longer applies in 2.0 because theAnthropicApitype and the matching constructor have been removed in favour of the officialcom.anthropic:anthropic-javaSDK; that step requires manual migration. -
For MCP (Model Context Protocol): adopt the new
spring-ai-mcp-annotationsartifact in place oforg.springaicommunity:mcp-annotations; move the MCP Spring WebFlux and WebMvc artifacts fromio.modelcontextprotocol.sdktoorg.springframework.ai; relocate the community MCP packages underorg.springaicommunity.mcp(annotation, context, method, provider) to the corresponding sub-packages oforg.springframework.ai.mcp.annotation; and move MCP transport types fromio.modelcontextprotocolto the correspondingorg.springframework.ai.mcp.{client,server}.{webflux,webmvc}.transportpackages. Replace deprecatedMcpSchemarecord constructors (TextContent,ReadResourceResult,GetPromptResult,ProgressNotification) with theirbuilder(…)factories. -
For Mistral AI: rename
MistralAiEmbeddingOptions.BuildermethodswithModel(…)andwithEncodingFormat(…)tomodel(…)andencodingFormat(…), and consolidate deprecatedMistralAiApi.ChatModelaliases onto their canonicalMISTRAL_*,MINISTRAL_*, andDEVSTRALnames. -
For OpenAI: rename the
spring-ai-openai-sdkandspring-ai-starter-model-openai-sdkartifacts to drop the-sdksuffix, and remove the Azure OpenAI artifacts (spring-ai-azure-openai,spring-ai-starter-model-azure-openai,spring-ai-autoconfigure-model-azure-openai), which have been discontinued in Spring AI 2.0. MigrateOpenAiApi.ChatModelconstants tocom.openai.models.ChatModelfrom the openai-java SDK (case-normalising names such asGPT_4_O→GPT_4O),OpenAiApi.EmbeddingModelconstants tocom.openai.models.embeddings.EmbeddingModel, andOpenAiImageApi.ImageModelconstants tocom.openai.models.images.ImageModel(fixing the upstreamGTP_IMAGE_1_MINItypo toGPT_IMAGE_1_MINIin the process). RenamegetValue()calls on these enums toasString()to match the openai-java API. Relocate the audio typesOpenAiAudioApi.SpeechRequest.VoiceandOpenAiAudioApi.SpeechRequest.AudioResponseFormattoOpenAiAudioSpeechOptions, and migrateOpenAiAudioApi.TranscriptResponseFormattocom.openai.models.audio.AudioResponseFormat. Relocateorg.springframework.ai.openai.api.ResponseFormattoOpenAiChatModel.ResponseFormatand replace the deprecatednew ResponseFormat(type, jsonSchema)constructor with the equivalentResponseFormat.builder().type(…).jsonSchema(…).build()form. Replace string-literalOpenAiEmbeddingOptions.Builder.encodingFormat(String)calls such as.encodingFormat("float")with the matchingOpenAiEmbeddingOptions.EncodingFormatenum constant. -
For Google: relocate
GoogleGenAiEmbeddingConnectionDetailsto theorg.springframework.ai.google.genai.embeddingsub-package. -
Remove the discontinued
spring-ai-hanadb-storeandspring-ai-spring-cloud-bindingsartifacts.
See its entry in the Recipe Catalog for the full list of recipes this upgrade applies, each with its options and a before/after example.
Run the Recipe
You can apply this recipe with any OpenRewrite-compatible tool. The tabs below show three of them: the Arconia CLI, the OpenRewrite Gradle plugin, and the OpenRewrite Maven plugin. See Running Recipes for a comparison of when to pick each one.
-
Arconia CLI
-
Gradle
-
Maven
arconia update spring-ai --to-version 2.0
First, create an init.gradle file in your project root with the following content.
initscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath("org.openrewrite:plugin:latest.release")
}
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite("io.arconia.migrations:rewrite-spring:latest.release")
}
// Remove when project repositories are disabled
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
mavenCentral()
}
}
}
configurations.named("rewrite") {
canBeConsumed = false
}
}
Then, run the following command.
./gradlew rewriteRun \
--init-script init.gradle \
--no-parallel \
-DactiveRecipe=io.arconia.rewrite.spring.ai2.UpgradeSpringAi_2_0
You can remove the init.gradle file afterwards.
./mvnw -U org.openrewrite.maven:rewrite-maven-plugin:run \
-Drewrite.recipeArtifactCoordinates=io.arconia.migrations:rewrite-spring:LATEST \
-Drewrite.activeRecipes=io.arconia.rewrite.spring.ai2.UpgradeSpringAi_2_0