spring-projects/spring-framework · error · IllegalArgumentException
Unknown advice kind [{}].
Error message
Unknown advice kind [{}]. What it means
Thrown by ConfigBeanDefinitionParser.getAdviceClass() in the default branch of the switch over the local element name when parsing an <aop:config><aspect> child element. Only the five advice element names are recognized (before, after, after-returning, after-throwing, around). Reaching the default branch means the parser was handed an element whose local name is none of these — which the XML schema should prevent, so this typically indicates a schema/custom-element processing issue.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java:412
}
cav.addIndexedArgumentValue(ASPECT_INSTANCE_FACTORY_INDEX, aspectFactoryDef);
return adviceDefinition;
}
/**
* Gets the advice implementation class corresponding to the supplied {@link Element}.
*/
private Class<?> getAdviceClass(Element adviceElement, ParserContext parserContext) {
String elementName = parserContext.getDelegate().getLocalName(adviceElement);
return switch (elementName) {
case BEFORE -> AspectJMethodBeforeAdvice.class;
case AFTER -> AspectJAfterAdvice.class;
case AFTER_RETURNING_ELEMENT -> AspectJAfterReturningAdvice.class;
case AFTER_THROWING_ELEMENT -> AspectJAfterThrowingAdvice.class;
case AROUND -> AspectJAroundAdvice.class;
default -> throw new IllegalArgumentException("Unknown advice kind [" + elementName + "].");
};
}
/**
* Parses the supplied {@code <pointcut>} and registers the resulting
* Pointcut with the BeanDefinitionRegistry.
*/
private AbstractBeanDefinition parsePointcut(Element pointcutElement, ParserContext parserContext) {
String id = pointcutElement.getAttribute(ID);
String expression = pointcutElement.getAttribute(EXPRESSION);
AbstractBeanDefinition pointcutDefinition = null;
try {
this.parseState.push(new PointcutEntry(id));
pointcutDefinition = createPointcutDefinition(expression);
pointcutDefinition.setSource(parserContext.extractSource(pointcutElement));
View on GitHub (pinned to e8729d0438)
Solutions
- Ensure the <aop:config> XML is schema-validated and uses only the five valid advice element names.
- Correct any typo in the advice element name (before, after, after-returning, after-throwing, around).
- Remove custom/unrecognized elements from inside <aspect>.
Example fix
<!-- before -->
<aop:config>
<aop:aspect ref="audit">
<aop:before-logging method="log" pointcut="execution(* *(..))"/>
</aop:aspect>
</aop:config>
<!-- after -->
<aop:config>
<aop:aspect ref="audit">
<aop:before method="log" pointcut="execution(* *(..))"/>
</aop:aspect>
</aop:config> Defensive patterns
Strategy: validation
Validate before calling
import org.w3c.dom.Element;
import java.util.Set;
void validateAdviceElements(Element aspectElement) {
Set<String> valid = Set.of("before","after","after-returning","after-throwing","around");
var kids = aspectElement.getChildNodes();
for (int i = 0; i < kids.getLength(); i++) {
if (kids.item(i) instanceof Element e && "aop".equals(e.getNamespaceURI()) && !valid.contains(e.getLocalName()))
throw new IllegalArgumentException("Unknown <aop:*> advice element: " + e.getLocalName());
}
} Prevention
- Keep XML schema validation enabled so invalid advice elements are rejected by the schema first.
- Use only the five canonical advice element names under <aop:aspect>.
- Prefer @AspectJ annotation style over XML <aop:config> to avoid hand-editing errors.
When it happens
Trigger: Parsing an <aop:config> document containing a child element under <aspect> whose local name is not one of before/after/after-returning/after-throwing/around, yet passed isAdviceNode filtering. Reachable if the XML schema validation is disabled or a custom namespace slips an unrecognized advice-like element in.
Common situations: Disabling XML schema validation and hand-editing <aop:config> with an invalid advice tag (e.g. <aop:after-completing>). A typo in an advice element name. A malformed namespace handler producing unexpected child elements.
Related errors
- Advice must be declared inside an aspect type: Offending met
- Property 'targetBeanName' is required
- Property 'methodName' is required
- MethodInvocation is not a Spring ProxyMethodInvocation: {}
- 'argumentNames' property of AbstractAspectJAdvice contains a
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/cc4c34fbf1a335f0.json.
Report an issue: GitHub.