Search before asking
Apache SkyWalking Component
Java Agent (apache/skywalking-java)
What happened
The Spring 6.x plugin (mvc-annotation-6.x-plugin) is being incorrectly activated when using Spring Framework 5.3.13, causing runtime errors due to API incompatibilities between Spring 5.x and Spring 6.x.
The issue is in the witness class selection in AbstractSpring6Instrumentation:
// AbstractSpring6Instrumentation.java
public static final String WITNESS_CLASSES = "org.springframework.web.servlet.resource.HttpResource";
The HttpResource class exists in Spring Framework since version 5.0 (as documented here), making it an imprecise witness class for detecting Spring 6.x.
Error Details
ERROR 2025-06-26 12:06:24.943 XNIO-1 task-4 InstMethodsInter : class[class org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod] after method[getBean] intercept failure java.lang.NoSuchMethodError: org.springframework.web.context.request.ServletRequestAttributes.getRequest()Ljakarta/servlet/http/HttpServletRequest; at org.apache.skywalking.apm.plugin.spring.mvc.v6.GetBeanInterceptor.afterMethod(GetBeanInterceptor.java:51)
Analysis
- Spring 5.3.13 uses
javax.servlet.* APIs
- Spring 6.x migrated to
jakarta.servlet.* APIs
- The
ServletRequestAttributes.getRequest() method returns different types:
- Spring 5.x:
javax.servlet.http.HttpServletRequest
- Spring 6.x:
jakarta.servlet.http.HttpServletRequest
- Since
HttpResource exists in both Spring 5.x and 6.x, the witness class check passes incorrectly
What you expected to happen
- Spring 5.x applications should activate the
mvc-annotation-5.x-plugin
- Spring 6.x applications should activate the
mvc-annotation-6.x-plugin
How to reproduce
- SkyWalking Version: 9.1.0
- Spring Framework Version: 5.3.13
- Java Version: 1.8
Anything else
Replace the witness class in AbstractSpring6Instrumentation with a class that only exists in Spring 6.x
Any recommended classes?
If my thinking is wrong, please tell me.
Are you willing to submit a pull request to fix on your own?
Code of Conduct
Search before asking
Apache SkyWalking Component
Java Agent (apache/skywalking-java)
What happened
The Spring 6.x plugin (
mvc-annotation-6.x-plugin) is being incorrectly activated when using Spring Framework 5.3.13, causing runtime errors due to API incompatibilities between Spring 5.x and Spring 6.x.The issue is in the witness class selection in
AbstractSpring6Instrumentation:The
HttpResourceclass exists in Spring Framework since version 5.0 (as documented here), making it an imprecise witness class for detecting Spring 6.x.Error Details
ERROR 2025-06-26 12:06:24.943 XNIO-1 task-4 InstMethodsInter : class[class org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod] after method[getBean] intercept failure java.lang.NoSuchMethodError: org.springframework.web.context.request.ServletRequestAttributes.getRequest()Ljakarta/servlet/http/HttpServletRequest; at org.apache.skywalking.apm.plugin.spring.mvc.v6.GetBeanInterceptor.afterMethod(GetBeanInterceptor.java:51)Analysis
javax.servlet.*APIsjakarta.servlet.*APIsServletRequestAttributes.getRequest()method returns different types:javax.servlet.http.HttpServletRequestjakarta.servlet.http.HttpServletRequestHttpResourceexists in both Spring 5.x and 6.x, the witness class check passes incorrectlyWhat you expected to happen
mvc-annotation-5.x-pluginmvc-annotation-6.x-pluginHow to reproduce
Anything else
Replace the witness class in
AbstractSpring6Instrumentationwith a class that only exists in Spring 6.xAny recommended classes?
If my thinking is wrong, please tell me.
Are you willing to submit a pull request to fix on your own?
Code of Conduct