{"record":{"id":"6c6f8fa7c691a5dd","repo":"spring-projects/spring-framework","slug":"unknown-advice-kind-elementname","errorCode":null,"errorMessage":"Unknown advice kind [{elementName}].","messagePattern":"Unknown advice kind \\[(.+?)\\]\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java","lineNumber":412,"sourceCode":"\t\t}\n\n\t\tcav.addIndexedArgumentValue(ASPECT_INSTANCE_FACTORY_INDEX, aspectFactoryDef);\n\n\t\treturn adviceDefinition;\n\t}\n\n\t/**\n\t * Gets the advice implementation class corresponding to the supplied {@link Element}.\n\t */\n\tprivate Class<?> getAdviceClass(Element adviceElement, ParserContext parserContext) {\n\t\tString elementName = parserContext.getDelegate().getLocalName(adviceElement);\n\t\treturn switch (elementName) {\n\t\t\tcase BEFORE -> AspectJMethodBeforeAdvice.class;\n\t\t\tcase AFTER -> AspectJAfterAdvice.class;\n\t\t\tcase AFTER_RETURNING_ELEMENT -> AspectJAfterReturningAdvice.class;\n\t\t\tcase AFTER_THROWING_ELEMENT -> AspectJAfterThrowingAdvice.class;\n\t\t\tcase AROUND -> AspectJAroundAdvice.class;\n\t\t\tdefault -> throw new IllegalArgumentException(\"Unknown advice kind [\" + elementName + \"].\");\n\t\t};\n\t}\n\n\t/**\n\t * Parses the supplied {@code <pointcut>} and registers the resulting\n\t * Pointcut with the BeanDefinitionRegistry.\n\t */\n\tprivate AbstractBeanDefinition parsePointcut(Element pointcutElement, ParserContext parserContext) {\n\t\tString id = pointcutElement.getAttribute(ID);\n\t\tString expression = pointcutElement.getAttribute(EXPRESSION);\n\n\t\tAbstractBeanDefinition pointcutDefinition = null;\n\n\t\ttry {\n\t\t\tthis.parseState.push(new PointcutEntry(id));\n\t\t\tpointcutDefinition = createPointcutDefinition(expression);\n\t\t\tpointcutDefinition.setSource(parserContext.extractSource(pointcutElement));\n","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java#L394-L430","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Correct the advice element name to one of: before, after, after-returning, after-throwing, around.","Validate the XML against the Spring AOP schema (http://www.springframework.org/schema/aop/spring-aop.xsd).","Check for typos in element names and namespace declarations."],"exampleFix":"<!-- before -->\n<aop:config>\n  <aop:aspect id=\"log\" ref=\"logAspect\">\n    <aop:after-runing method=\"after\" pointcut=\"execution(* com.example.*.*(..))\"/>\n  </aop:aspect>\n</aop:config>\n<!-- after -->\n<aop:config>\n  <aop:aspect id=\"log\" ref=\"logAspect\">\n    <aop:after-returning method=\"after\" pointcut=\"execution(* com.example.*.*(..))\"/>\n  </aop:aspect>\n</aop:config>","handlingStrategy":"validation","validationCode":"import java.util.Set;\n\npublic static boolean isValidAdviceElementName(String name) {\n    return Set.of(\"before\", \"after\", \"after-returning\", \"after-throwing\", \"around\").contains(name);\n}\n\n// when programmatically building/inspecting <aop:aspect> children:\nif (!isValidAdviceElementName(element.getLocalName())) {\n    throw new IllegalArgumentException(\"Unknown <aop:aspect> advice element: \" + element.getLocalName());\n}","typeGuard":null,"tryCatchPattern":"// XML parsing errors surface as context-load failures; validate the schema up front instead.\n// Use a Schema-validating XML loader for Spring AOP config files.\ntry {\n    new GenericXmlApplicationContext(\"classpath:aop-config.xml\");\n} catch (IllegalArgumentException ex) {\n    if (ex.getMessage().startsWith(\"Unknown advice kind\")) {\n        // fix the typo'd advice element name in the XML\n    } else throw ex;\n}","preventionTips":["Validate Spring AOP XML against http://www.springframework.org/schema/aop/spring-aop.xsd in the IDE/build.","Use the schema-aware XML editor to catch typos in advice element names at edit time.","Prefer @AspectJ annotation style over XML to avoid element-name typos."],"tags":["spring-aop","xml-configuration","namespace","configuration"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}