spring-projects/spring-framework · error · UnknownAdviceTypeException
Advice object [{adviceObject}] is neither a supported subint
Error message
Advice object [{adviceObject}] is neither a supported subinterface of [org.aopalliance.aop.Advice] nor an [org.springframework.aop.Advisor] What it means
DefaultAdvisorAdapterRegistry.wrap() throws UnknownAdviceTypeException when the object passed is not an Advisor and not even an instance of org.aopalliance.aop.Advice. The adapters (MethodBefore/AfterReturning/Throws) only know how to wrap actual Advice subinterfaces, so a plain object is rejected at this first type check.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java:65
/**
* Create a new DefaultAdvisorAdapterRegistry, registering well-known adapters.
*/
public DefaultAdvisorAdapterRegistry() {
registerAdvisorAdapter(new MethodBeforeAdviceAdapter());
registerAdvisorAdapter(new AfterReturningAdviceAdapter());
registerAdvisorAdapter(new ThrowsAdviceAdapter());
}
@Override
public Advisor wrap(Object adviceObject) throws UnknownAdviceTypeException {
if (adviceObject instanceof Advisor advisor) {
return advisor;
}
if (!(adviceObject instanceof Advice advice)) {
throw new UnknownAdviceTypeException(adviceObject);
}
if (advice instanceof MethodInterceptor) {
// So well-known it doesn't even need an adapter.
return new DefaultPointcutAdvisor(advice);
}
for (AdvisorAdapter adapter : this.adapters) {
// Check that it is supported.
if (adapter.supportsAdvice(advice)) {
return new DefaultPointcutAdvisor(advice);
}
}
throw new UnknownAdviceTypeException(advice);
}
@Override
public MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException {
List<MethodInterceptor> interceptors = new ArrayList<>(3);
Advice advice = advisor.getAdvice();View on GitHub (pinned to e8729d0438)
Solutions
- Make the advice class implement MethodInterceptor, MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice, or Advisor.
- Verify the bean you pass to wrap()/addAdvice() is actually typed as Advice in your configuration.
- If wrapping a third-party interceptor, adapt it with a custom AdvisorAdapter.
Example fix
// before
class MyLogger { void log() {} } // not an Advice
factory.addAdvice(new MyLogger());
// after
class MyLogger implements MethodBeforeAdvice {
public void before(Method m, Object[] args, Object target) { log(); }
}
factory.addAdvice(new MyLogger()); Defensive patterns
Strategy: type-guard
Validate before calling
public void safeAddAdvice(Advised advised, Object candidate) {
if (!(candidate instanceof org.aopalliance.aop.Advice)
&& !(candidate instanceof org.springframework.aop.Advisor)) {
throw new IllegalArgumentException("Not Advice/Advisor: " + candidate);
}
advised.addAdvice((org.aopalliance.aop.Advice) candidate);
} Type guard
public static boolean isAdviceOrAdvisor(Object o) {
return o instanceof org.aopalliance.aop.Advice || o instanceof org.springframework.aop.Advisor;
} Try / catch
try {
registry.wrap(candidate);
} catch (UnknownAdviceTypeException ex) {
throw new IllegalArgumentException(candidate + " must implement Advice or Advisor", ex);
} Prevention
- Implement MethodInterceptor/MethodBeforeAdvice/AfterReturningAdvice/ThrowsAdvice or Advisor on advice classes.
- Type-check the object with instanceof before passing to wrap/addAdvice.
- Wire advice beans by type, not by name, to catch mismatches at injection time.
When it happens
Trigger: Passing a raw POJO (no Advice/Advisor interface) to wrap(); calling addAdvice() / addAdvisor() on an Advised with an unsupported object; misconfigured interceptor that is the wrong type.
Common situations: Registering a plain bean as advice instead of a MethodBeforeAdvice/MethodInterceptor/etc.; copy-paste wiring pointing at the wrong bean; classpath has an older advice class missing the interface.
Related errors
- Unknown advisor type {next.getClass()}; can only include Adv
- Advice object [{advice}] is neither a supported subinterface
- Cannot invoke methods: {message}
- Advice object [{advisor.getAdvice()}] is neither a supported
- Mismatch on arguments to advice method [{}]; pointcut expres
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/9f936b5a7c221f16.json.
Report an issue: GitHub.