spring-projects/spring-framework · error · AopInvocationException
AOP configuration seems to be invalid: tried calling method
Error message
AOP configuration seems to be invalid: tried calling method [{method}] on target [{target}] What it means
invokeJoinpointUsingReflection wraps an IllegalArgumentException thrown by Method.invoke as AopInvocationException with the message 'AOP configuration seems to be invalid'. IllegalArgumentException from reflect typically means the supplied arguments do not match the method's signature, or the method belongs to a class incompatible with the target object. It signals a misalignment between the proxied method and the actual target.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java:367
* @throws org.springframework.aop.AopInvocationException in case of a reflection error
*/
public static @Nullable Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, @Nullable Object[] args)
throws Throwable {
// Use reflection to invoke the method.
try {
Method originalMethod = BridgeMethodResolver.findBridgedMethod(method);
ReflectionUtils.makeAccessible(originalMethod);
return (COROUTINES_REACTOR_PRESENT && KotlinDetector.isSuspendingFunction(originalMethod) ?
KotlinDelegate.invokeSuspendingFunction(originalMethod, target, args) : originalMethod.invoke(target, args));
}
catch (InvocationTargetException ex) {
// Invoked method threw a checked exception.
// We must rethrow it. The client won't see the interceptor.
throw ex.getTargetException();
}
catch (IllegalArgumentException ex) {
throw new AopInvocationException("AOP configuration seems to be invalid: tried calling method [" +
method + "] on target [" + target + "]", ex);
}
catch (IllegalAccessException | InaccessibleObjectException ex) {
throw new AopInvocationException("Could not access method [" + method + "]", ex);
}
}
/**
* Inner class to avoid a hard dependency on Kotlin at runtime.
*/
private static class KotlinDelegate {
public static Object invokeSuspendingFunction(Method method, @Nullable Object target, @Nullable Object... args) {
Continuation<?> continuation = (Continuation<?>) args[args.length -1];
Assert.state(continuation != null, "No Continuation available");
CoroutineContext context = continuation.getContext().minusKey(Job.Key);
return CoroutinesUtils.invokeSuspendingFunction(context, method, target, args);View on GitHub (pinned to e8729d0438)
Solutions
- Verify the target object is an instance of the method's declaring class and that arg types match.
- Clean-rebuild to eliminate stale classes / hot-swapped bytecode mismatches.
- Check for classloader conflicts (same class loaded twice) and align versions.
Defensive patterns
Strategy: try-catch
Validate before calling
if (target == null || !method.getDeclaringClass().isInstance(target)) {
throw new IllegalStateException("target/method mismatch for " + method);
} Type guard
boolean argsMatch(java.lang.reflect.Method m, Object[] args) {
Class<?>[] params = m.getParameterTypes();
if (params.length != (args == null ? 0 : args.length)) return false;
for (int i = 0; i < params.length; i++) {
if (args[i] != null && !params[i].isInstance(args[i])) return false;
}
return true;
} Try / catch
try {
return AopUtils.invokeJoinpointUsingReflection(target, method, args);
} catch (AopInvocationException ex) {
// log target/method/args mismatch; surface config error
throw ex;
} Prevention
- Keep proxy and target classloaders consistent to avoid stale classes.
- Clean-rebuild after refactoring advised interfaces.
- Validate method/target/args alignment in unit tests for manual invocations.
When it happens
Trigger: The AOP runtime calls Method.invoke(target, args) where args' types/count disagree with the resolved Method, or target is not an instance of method.getDeclaringClass().
Common situations: Stale proxies after class reloading/hot-swap; bridge/generics resolution bugs; inconsistent class versions across classloaders; manual ReflectiveMethodInvocation built with mismatched method/target/args.
Related errors
- Unable to locate method [{}] on bean [{}]
- MethodInvocation is not a Spring ProxyMethodInvocation: {}
- 'argumentNames' property of AbstractAspectJAdvice contains a
- Only afterReturning advice can be used to bind a return valu
- Only afterThrowing advice can be used to bind a thrown excep
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/2fb61baf40a6bd81.json.
Report an issue: GitHub.