spring-projects/spring-framework · error · AopConfigException

Unable to instantiate aspect class: {}

Error message

Unable to instantiate aspect class: {}

What it means

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.

Source

Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java:68

	/**
	 * Return the specified aspect class (never {@code null}).
	 */
	public final Class<?> getAspectClass() {
		return this.aspectClass;
	}

	@Override
	public final Object getAspectInstance() {
		try {
			return ReflectionUtils.accessibleConstructor(this.aspectClass).newInstance();
		}
		catch (NoSuchMethodException ex) {
			throw new AopConfigException(
					"No default constructor on aspect class: " + this.aspectClass.getName(), ex);
		}
		catch (InstantiationException ex) {
			throw new AopConfigException(
					"Unable to instantiate aspect class: " + this.aspectClass.getName(), ex);
		}
		catch (IllegalAccessException | InaccessibleObjectException ex) {
			throw new AopConfigException(
					"Could not access aspect constructor: " + this.aspectClass.getName(), ex);
		}
		catch (InvocationTargetException ex) {
			throw new AopConfigException(
					"Failed to invoke aspect constructor: " + this.aspectClass.getName(), ex.getTargetException());
		}
	}

	@Override
	public @Nullable ClassLoader getAspectClassLoader() {
		return this.aspectClass.getClassLoader();
	}

	/**

View on GitHub (pinned to e8729d0438)

Solutions

  1. Register the concrete subclass of the aspect, not the abstract base or interface.
  2. Verify the Class passed to SimpleAspectInstanceFactory is concrete and instantiable.
  3. Ensure the aspect class is not marked abstract.

Example fix

// before
new SimpleAspectInstanceFactory(AbstractAuditAspect.class);

// after
new SimpleAspectInstanceFactory(ConcreteAuditAspect.class);
Defensive patterns

Strategy: validation

Validate before calling

int mods = aspectClass.getModifiers();
if (Modifier.isAbstract(mods) || aspectClass.isInterface() || !Modifier.isPublic(mods)) {
    throw new IllegalStateException("Aspect class must be concrete and public: " + aspectClass);
}

Type guard

boolean instantiable = !Modifier.isAbstract(aspectClass.getModifiers())
    && !aspectClass.isInterface() && !aspectClass.isPrimitive();

Prevention

When it happens

Trigger: Registering an abstract aspect class, an interface, or a non-instantiable class with SimpleAspectInstanceFactory.

Common situations: Registering an abstract base aspect by mistake; passing an interface Class object; generic aspect base classes accidentally wired as concrete aspects.

Related errors


AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04). Data as JSON: /data/errors/122f3bbecbfcfbfa.json. Report an issue: GitHub.