{"id":"122f3bbecbfcfbfa","repo":"spring-projects/spring-framework","slug":"unable-to-instantiate-aspect-class","errorCode":null,"errorMessage":"Unable to instantiate aspect class: {}","messagePattern":"Unable to instantiate aspect class: (.+?)","errorType":"exception","errorClass":"AopConfigException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java","lineNumber":68,"sourceCode":"\n\t/**\n\t * Return the specified aspect class (never {@code null}).\n\t */\n\tpublic final Class<?> getAspectClass() {\n\t\treturn this.aspectClass;\n\t}\n\n\t@Override\n\tpublic final Object getAspectInstance() {\n\t\ttry {\n\t\t\treturn ReflectionUtils.accessibleConstructor(this.aspectClass).newInstance();\n\t\t}\n\t\tcatch (NoSuchMethodException ex) {\n\t\t\tthrow new AopConfigException(\n\t\t\t\t\t\"No default constructor on aspect class: \" + this.aspectClass.getName(), ex);\n\t\t}\n\t\tcatch (InstantiationException ex) {\n\t\t\tthrow new AopConfigException(\n\t\t\t\t\t\"Unable to instantiate aspect class: \" + this.aspectClass.getName(), ex);\n\t\t}\n\t\tcatch (IllegalAccessException | InaccessibleObjectException ex) {\n\t\t\tthrow new AopConfigException(\n\t\t\t\t\t\"Could not access aspect constructor: \" + this.aspectClass.getName(), ex);\n\t\t}\n\t\tcatch (InvocationTargetException ex) {\n\t\t\tthrow new AopConfigException(\n\t\t\t\t\t\"Failed to invoke aspect constructor: \" + this.aspectClass.getName(), ex.getTargetException());\n\t\t}\n\t}\n\n\t@Override\n\tpublic @Nullable ClassLoader getAspectClassLoader() {\n\t\treturn this.aspectClass.getClassLoader();\n\t}\n\n\t/**","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java#L50-L86","documentation":"Thrown by SimpleAspectInstanceFactory.getAspectInstance when Constructor.newInstance raises InstantiationException — the aspect class is abstract, an interface, an array class, a primitive, or void, so it cannot be instantiated. Spring attempted to create an instance reflectively but the JVM refused.","triggerScenarios":"Registering an abstract aspect class, an interface, or a non-instantiable class with SimpleAspectInstanceFactory.","commonSituations":"Registering an abstract base aspect by mistake; passing an interface Class object; generic aspect base classes accidentally wired as concrete aspects.","solutions":["Register the concrete subclass of the aspect, not the abstract base or interface.","Verify the Class passed to SimpleAspectInstanceFactory is concrete and instantiable.","Ensure the aspect class is not marked abstract."],"exampleFix":"// before\nnew SimpleAspectInstanceFactory(AbstractAuditAspect.class);\n\n// after\nnew SimpleAspectInstanceFactory(ConcreteAuditAspect.class);","handlingStrategy":"validation","validationCode":"int mods = aspectClass.getModifiers();\nif (Modifier.isAbstract(mods) || aspectClass.isInterface() || !Modifier.isPublic(mods)) {\n    throw new IllegalStateException(\"Aspect class must be concrete and public: \" + aspectClass);\n}","typeGuard":"boolean instantiable = !Modifier.isAbstract(aspectClass.getModifiers())\n    && !aspectClass.isInterface() && !aspectClass.isPrimitive();","tryCatchPattern":null,"preventionTips":["Register only concrete aspect subclasses.","Validate the class is instantiable before wiring it as an aspect.","Keep base aspects abstract and register subclasses."],"tags":["spring-aop","aspectj","aspect-instantiation","reflection"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}