AOP(3): Spring AOP

AOP References

  1. Please refer to Spring Framework AOP specification site for more details on spring aop concepts.
  2. General introduction to Aspect-Oriented Programming

Aspect

Aspect is "cross-cutting concern". For example:

  1. Transaction Management Aspect
  2. Logging Aspect  
  3. Security Aspect 

Transaction Management Aspect

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 Aspect

There 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 Aspect

Logging 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.

Pointcut

In 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(..))
 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值