Advised class abstract interface

The interface every generated AOP proxy implements: it exposes the bean behind the proxy and the advice applied to it.

A bean that some advice matches is replaced by its proxy, so the object getBean returns or another bean receives may be an Advised. Check for it to find out which advisors apply (in a test or a diagnostic page), to reach the real object, or to change the advice of a live proxy. Most applications never touch it; AopUtils covers the common "is this a proxy, what is behind it" questions.

// In a test: is the Calculator advised, and by what?
final calculator = context.getBean<Calculator>();
if (calculator is Advised) {
  log.info(calculator.aopTarget); // the SimpleCalculator
  log.info(calculator.aopAdvisors);
}

Spring (Java):

Calculator calculator = context.getBean(Calculator.class);
if (calculator instanceof Advised advised) {
  log.info("{}", advised.getTargetSource().getTarget());
  log.info(Arrays.toString(advised.getAdvisors()));
}

A generated subclass proxy (for a class that cannot be implemented) is the bean itself: its aopTarget is the proxy. Such a bean implements Advised even when no advice matched it; then it has no advisors, and the methods that change them throw an AopConfigException.

Advisors can be added and removed at runtime, like Spring's Advised.addAdvisor / removeAdvisor: the next call of an affected member uses the new chain.

// Turn on call logging for a live bean, for example while debugging.
(calculator as Advised).addAdvice(LoggingInterceptor());

Spring (Java):

((Advised) calculator).addAdvice(new LoggingInterceptor());

Properties

aopAdvisors → List<PointcutAdvisor>
The advisors that apply to this proxy, outermost first; empty for a subclass proxy no advice matched.
no setter
aopTarget → Object
The bean behind the proxy; the proxy itself for a generated subclass proxy.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addAdvice(MethodInterceptor advice) → void
Appends advice as the innermost advice of every member, wrapped in a DefaultPointcutAdvisor with a TruePointcut (as Spring's addAdvice does). Throws like addAdvisor.
addAdvisor(PointcutAdvisor advisor) → void
Appends advisor as the innermost one; the next calls of the members its pointcut matches run it.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeAdvice(MethodInterceptor advice) → bool
Removes the first advisor whose advice is advice (the same object); returns false when there is none.
removeAdvisor(PointcutAdvisor advisor) → bool
Removes advisor; returns false when it was not there.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited