AOP(3): Spring AOP
Aspect is "cross-cutting concern". For example:
Transaction is required in many enterprise application:
?
Before launch an operation, we should initialize an transaction to make sure the operation is atomic.After each operation, we should make sure transaction is submit.If any error happen during operation, we should make sure the Transaction rollback....?
All of those requirements are common to each enterprise applications regardless of the business requirements.
Security AspectThere are many approaches to authenticate and authorize user's permission to manipulate specific system resources. Security Aspect can solve the scenario like:?
?
Some Methods can only be invoked by invoker who has specific permission. And all those checkings are before invocation.Some User Interface or operation can only be show to specific user roles....?
For example, ?Acegi and Spring security will manage security with AOP ascpect.
Logging AspectLogging is necessary requirement for all enterprise applications. We can use logging to trace/monitor the system status:
?
Trace methods invocation start/complete/failed...Trace user operation on the server...Trace data transmitting state during business logical......All those functions are common and not related to any business. We can manage logging in AOP aspect.
PointcutIn Spring AOP, "Pointcut" define the points where aspect operations should be injected during business logical running.?In Spring AOP, a join point always represents a method execution.
There are several kinds of Pointcut definition.
The execution of any public method?execution(public * *(..))
?
The execution of any method with a name beginning with "set"?
execution(* set*(..))??The execution of any method defined by the AccountService interface?
execution(* com.xyz.service.AccountService.*(..))??The execution of the process method taking a String in argument?
execution(public * com.xyz.service.BillingService.process(String))The execution of the process method taking any argument, returning an Integer?
execution(public Integer com.xyz.service.BillingService.process(..))?
?