spring-projects/spring-framework · error · IllegalArgumentException

Unknown advice kind [{elementName}].

Error message

Unknown advice kind [{elementName}].

What it means

Thrown as an IllegalArgumentException from ConfigBeanDefinitionParser.getAdviceClass(Element, ParserContext) when an <aop:config>/<aop:aspect> child element's local name is not one of the recognized advice kinds: 'before', 'after', 'after-returning', 'after-throwing', or 'around'. This is XML-schema parsing code; the switch maps element names to advice implementation classes, and the default branch rejects any unknown advice element.

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 69bf83ad71)

Solutions

  1. Correct the advice element name to one of: before, after, after-returning, after-throwing, around.
  2. Validate the XML against the Spring AOP schema (http://www.springframework.org/schema/aop/spring-aop.xsd).
  3. Check for typos in element names and namespace declarations.

Example fix

<!-- before -->
<aop:config>
  <aop:aspect id="log" ref="logAspect">
    <aop:after-runing method="after" pointcut="execution(* com.example.*.*(..))"/>
  </aop:aspect>
</aop:config>
<!-- after -->
<aop:config>
  <aop:aspect id="log" ref="logAspect">
    <aop:after-returning method="after" pointcut="execution(* com.example.*.*(..))"/>
  </aop:aspect>
</aop:config>
Defensive patterns

Strategy: validation

Validate before calling

import java.util.Set;

public static boolean isValidAdviceElementName(String name) {
    return Set.of("before", "after", "after-returning", "after-throwing", "around").contains(name);
}

// when programmatically building/inspecting <aop:aspect> children:
if (!isValidAdviceElementName(element.getLocalName())) {
    throw new IllegalArgumentException("Unknown <aop:aspect> advice element: " + element.getLocalName());
}

Try / catch

// XML parsing errors surface as context-load failures; validate the schema up front instead.
// Use a Schema-validating XML loader for Spring AOP config files.
try {
    new GenericXmlApplicationContext("classpath:aop-config.xml");
} catch (IllegalArgumentException ex) {
    if (ex.getMessage().startsWith("Unknown advice kind")) {
        // fix the typo'd advice element name in the XML
    } else throw ex;
}

Prevention

When it happens

Trigger: Hand-written or programmatically constructed AOP XML containing a typo'd or unsupported element inside <aop:aspect> (e.g., <aop:after-runing> instead of <aop:after-returning>, or a custom element); an XML schema/namespace mix-up producing an unexpected child element; a malformed namespace handler.

Common situations: Typos in Spring AOP XML configuration; copy-pasting XML snippets that use a non-existent advice element; version differences where an older/newer schema is applied; namespace handler customization errors.

Related errors


AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09). Data as JSON: /api/errors/6c6f8fa7c691a5dd. Report an issue: GitHub.