AopProxyFactory class final
Knows how to wrap one bean class in its generated proxy class, and which of its members can be advised.
Dart cannot create classes at runtime, so the generator writes a proxy
class for each bean class and attaches one of these factories to the
bean definition (its aopProxy field). When the context starts, the
AspectAutoProxyCreator asks it which advisors match the bean and has
it create the proxy. There are three forms: a wrapper class that
implements the bean's class or interfaces and forwards to it (the main
constructor), a generated subclass the bean is created as
(AopProxyFactory.subclass), and a placeholder for beans that cannot be
proxied (AopProxyFactory.unavailable). Applications do not create it;
ProxyFactory.forBean uses it to make more proxies of a bean.
Unlike Spring's JDK and CGLIB proxies, the proxy class is written at build time, so no reflection is needed at runtime.
// In a test, with a proxy class CalculatorProxy written by hand:
// wrap a SimpleCalculator so every call is logged.
final factory = AopProxyFactory(
signatures: CalculatorProxy.signatures,
create: (target, invoker) =>
CalculatorProxy(target as SimpleCalculator, invoker),
);
final Calculator proxy = factory.createProxy(
SimpleCalculator(),
[DefaultPointcutAdvisor(const TruePointcut(), LoggingInterceptor())],
) as Calculator;
Spring (Java):
ProxyFactory factory = new ProxyFactory(new SimpleCalculator());
factory.addAdvisor(
new DefaultPointcutAdvisor(Pointcut.TRUE, new LoggingInterceptor()));
Calculator proxy = (Calculator) factory.getProxy();
Constructors
-
AopProxyFactory({required List<
MethodSignature> signatures, required Object create(Object target, ProxyInvoker invoker), List<Introduction> introductions = const [], Set<String> ? knownAdvisors}) -
A factory for a wrapper proxy class whose advisable members are
signatures;createinstantiates the generated class around a target. -
AopProxyFactory.deferred({required List<
MethodSignature> signatures}) -
A bean of a library package whose proxy class the build of the
application writes, only when one of its pointcuts may match it: the
library's build cannot know the application's aspects.
const
-
AopProxyFactory.pruned({String? reason, Set<
String> ? knownAdvisors = const <String>{}}) -
A bean the build gave no proxy class: no pointcut it knows of matches
the bean (
reasonsays so, prunedReason when not given). Nothing is generated for its members, so the context fails at startup with an AopConfigException when an aspect or advisor bean the build did not know of (knownAdvisors, none when not given) is registered, and the bean cannot get advice at run time; build with the optionaop_prune: falseto keep every proxy.const -
AopProxyFactory.subclass({required List<
MethodSignature> signatures, required Object? advise(Object bean, ProxyInvoker invoker), List<Introduction> introductions = const [], Set<String> ? knownAdvisors}) - A factory for a bean whose class cannot be implemented but can be extended, which the container creates as a generated subclass.
-
A placeholder for a bean whose class cannot be proxied, with the
reason.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
introductions
→ List<
Introduction> -
The interfaces the proxy class implements for
@DeclareParents; the proxy refers to each by its index in ProxyInvoker.introduction.final - isDeferred → bool
-
Whether this is an AopProxyFactory.deferred placeholder, which the
application's factory for the bean replaces.
final
- isPartial → bool
-
Whether the proxy class intercepts only the members the build found
advice for (signatures); the others call the bean directly, so
advisors cannot be added to such a proxy at run time.
no setter
- isSubclass → bool
-
Whether the bean is created as a generated subclass that advice is
attached to, instead of being wrapped.
no setter
-
knownAdvisors
→ Set<
String> ? -
For a factory the build pruned (AopProxyFactory.pruned, or a
partial proxy class, isPartial): the
sources of the aspect and advisor bean definitions it knew of. An entry without#stands for a whole package (package:spring_boot_starter_data): the definitions whose source starts with it and/or#.nullfor a factory the build did not prune.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
signatures
→ List<
MethodSignature> -
The bean's advisable members; the generated proxy refers to each by
its index in this list.
final
-
Why the bean cannot be proxied;
nullwhen it can.final
Methods
-
createProxy(
Object target, List< PointcutAdvisor> advisors, {String beanName = '', List<String> beanAliases = const []}) → Object -
Returns the proxy of
targetthat runsadvisors, outermost first. -
eligibleAdvisors(
List< PointcutAdvisor> advisors, String beanName, {List<String> beanAliases = const []}) → List<PointcutAdvisor> -
The advisors among
advisorsthat match at least one member of the bean namedbeanName, in their order.beanAliases(the bean's aliases and qualifier values) also count forbean(...)pointcuts. An empty result means the bean needs no proxy. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- deferredReason → const String
- The unavailableReason of AopProxyFactory.deferred.
- prunedReason → const String
- The unavailableReason of AopProxyFactory.pruned when the build gave none (it writes none, so release builds carry one copy of it).