Spring Study[6]

Aspect:
An aspect is the cross-cutting functionality you are implementing.The most common (albeit simple) example of an aspect is logging.
Joinpoint:
A joinpoint is a point in the execution of the application where an aspect can be plugged in.This point could be a method being called, an exception being thrown, or even a field being modified.
Advice:
Advice is the actual implementation of our aspect.
Pointcut:
A pointcut defines at what joinpoints advice should be applied.
Introduction:
An introduction allows you to add new methods or attributes to existing classes (kind of mind-blowing, huh?).
Target:
A target is the class that is being advised.
Proxy:
A proxy is the object created after applying advice to the target object.
Weaving:
Weaving is the process of applying aspects to a target object to create a new, proxied object.

All of the advice you create within Spring will be written in a standard Java class.

the pointcuts that define where advice should be applied are typically written in XML in your Spring configuration file.

Other frameworks out there, specifically AspectJ, require a special syntax to write the aspect and define pointcuts.

If you are using an ApplicationContext, the proxied objects will be created when it loads all of the beans from the BeanFactory. Because Spring creates proxies at runtime, you do not need a special compiler to use Spring’s AOP.

Spring only supports method joinpoints

Advice type Interface Description
Around org.aopalliance.intercept.MethodInterceptor Intercepts calls to the target
method
Before org.springframework.aop.BeforeAdvice Called before the target
method is invoked
After org.springframework.aop.AfterReturningAdvice Called after the target
method returns
Throws org.springframework.aop.ThrowsAdvice Called when target
method throws an
exception

Before advice:
To accomplish this, we extend the MethodBeforeAdvice interface:
This interface provides you with access to the target method.

The only way MethodBeforeAdvice can prevent the target method from being invoked is to throw an exception (or call System.
exit(), but we don’t want to do that!).If the exception is a RuntimeException or if it is in the throws clause of the target method, it will propagate to the calling method. Otherwise, Spring’s framework will catch the exception and rethrow it wrapped in a RuntimeException.

we created this bean using Spring’s ProxyFactoryBean class. This is also your introduction to this very important class in Spring’s AOP framework.

we tell Spring to create a bean that does the following:
■ Implements the KwikEMart interface
■ Applies the WelcomeAdvice (id welcomeAdvice) advice object to all incoming calls
■ Uses the ApuKwikEMart bean (id kwikEMartTarget) as the target object

After advice:
we implement AfterReturningAdvice.

你可能感兴趣的:(spring)