Skip to content

Cannot exclude certain auto-configurations in a consuming Boot application #4494

@Kehrlann

Description

@Kehrlann

Bug description

There is a special case in MCP tools, where excluding the ToolCallingAutoConfiguration would be desirable. In a regular Boot application, this would be achieved through:

@SpringBootApplication(exclude = { ToolCallingAutoConfiguration.class })
public class SampleMcpClientWebfluxApplication {

//...

}

However, this does exclude the configuration, because, in my application, I use Anthropic and AnthropicChatAutoConfiguration. But that auto-configuration pulls in ToolCallingAutoConfiguration (source), which cannot be excluded independently anymore.

Environment

Spring AI 1.0.x and 1.1.x are affected.

Expected behavior

It is possible to work around this specific case, but it requires diving into the auto-configurations and figuring their dependencies.
I think using @ImportAutoConfiguration on auto-configuration classes is an anti-pattern, because it breaks the "exclusion" part of the auto-configuration contract.

What should really happen in this case is that:

  1. Conditions for ToolCallingAutoConfiguration are fulfilled, so it is actiaved.
  2. Conditions for AnthropicChatAutoConfiguration are fulfilled, so it is activated.
  3. Anthropic is marked @AutoConfiguration(after = {ToolCallingAutoConfiguration.class}), so the ordering is taking care of for me.

By doing so, it becomes possible for users to disable auto-configurations.

Problematic classes

Each of those can be fixed independently, see #4495 for Ollama.

Fix

All @ImportAutoConfiguration should be removed. I don't know of any project who uses that annotation (if you'd like to check, their starters are in Boot directly).

This might break existing behavior, and would require thinking about the auto-configuration of excluded classes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions