AOP(3):Spring AOP
3065 ワード
AOP References Please refer to Spring Fraamewark AOP specification site for more details on spring aop concepts. General introduction to Asppect-Orinted Programe ming Asppect
Aspect is「cross-cutting concern」.For example: Transact Management Aspect ロギングAspect Security Aspect Transaction Management Aspect
Transaction is required in many enterpris aplication:
Before launch an operation,we shound initialize an transaction to make sure the operation is atomic. After each operation,we shoud make sure transpaction is submit. If any error happen during operation,we shoud make sure the Transation rollback. …
All of those requirements aremon to each enterprisations regardless of the business requirements.
Security Asppect
The e are many authenticate and authorize user's permission to manippulate specific system.Security Aspect can solive the scenare:
Some Methods can only be invoked by invoker whos specific permission.And all those checks are before invocation. Some User Interface or operation can only be show to specific user roles. …
For example、 Acegi and Spring security will mage security with AOP ascpect.
ロギングAsppect
ロギングis necessary requirement for all enterpress.We can use loging to trace/monitor the system status:
Trace methods invocation start/compplete/failed… Trace user operation on the server… Trace data transmitting state during busines logcal… … All those functions are common and not related to any business.We can manage loging in AOP aspect.
Pointcut
In Spring AOP、「Pointcut」define the points where aspect operation s shoruld be injeced during business logrunning. In Spring AOP,a join point always represents a method execution.
The re are several kids of Pointcut definition.
The execution of any public method
The execution of any method with a name begining with「set」
The execution of any method defined by the AcceountService interface
The execution of the process method taring a String in argment
Aspect is「cross-cutting concern」.For example:
Transaction is required in many enterpris aplication:
All of those requirements aremon to each enterprisations regardless of the business requirements.
Security Asppect
The e are many authenticate and authorize user's permission to manippulate specific system.Security Aspect can solive the scenare:
For example、 Acegi and Spring security will mage security with AOP ascpect.
ロギングAsppect
ロギングis necessary requirement for all enterpress.We can use loging to trace/monitor the system status:
Pointcut
In Spring AOP、「Pointcut」define the points where aspect operation s shoruld be injeced during business logrunning. In Spring AOP,a join point always represents a method execution.
The re are several kids of Pointcut definition.
The execution of any public method
execution(public * *(..))
The execution of any method with a name begining with「set」
execution(* set*(..))
The execution of any method defined by the AcceountService interface
execution(* com.xyz.service.AccountService.*(..))
The execution of the process method taring a String in argment
execution(public * com.xyz.service.BillingService.process(String))
The execution of the process method tang any argment,returning an Integer execution(public Integer com.xyz.service.BillingService.process(..))