-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
IllegalArgumentException: Class must not be null after upgrading to Spring AI MCP Client 1.1.0
Description:
After upgrading from Spring AI version 1.0.3 to 1.1.0, my application fails to start with the following error:
java.lang.IllegalArgumentException: Class must not be null
at org.springframework.util.Assert.notNull(Assert.java:181)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:461)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:360)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:342)
at org.springframework.ai.mcp.annotation.spring.AbstractClientMcpHandlerRegistry.scan(AbstractClientMcpHandlerRegistry.java:128)
at org.springframework.ai.mcp.annotation.spring.AbstractClientMcpHandlerRegistry.postProcessBeanFactory(AbstractClientMcpHandlerRegistry.java:77)
at org.springframework.ai.mcp.annotation.spring.ClientMcpSyncHandlersRegistry.postProcessBeanFactory(ClientMcpSyncHandlersRegistry.java:65)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:363)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:204)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:791)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:609)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
Dependencies used:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-client</artifactId>
</dependency>Root Cause Analysis:
The error originates from this line in AbstractClientMcpHandlerRegistry.java#L77:
Class<?> targetClass = AutoProxyUtils.determineTargetClass(beanFactory, beanName);For the bean named shiroFilter, AutoProxyUtils.determineTargetClass(...) returns null. Although the bean definition exists in the beanFactory and can be retrieved normally, the internal call bd.getAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE) returns null.
The shiroFilter bean is defined in ShiroAutoConfiguration.java
This worked perfectly in Spring AI 1.0.3, but breaks in 1.1.0.
Expected Behavior:
The application should start without throwing an IllegalArgumentException when scanning MCP handler beans, even if some beans (like shiroFilter) do not have a resolvable target class via AutoProxyUtils.determineTargetClass.
Suggested Fix:
Add a null check before calling ReflectionUtils.doWithMethods(targetClass, ...) to skip beans where targetClass is null. But I don't know if it's right.