首页 > 编程语言 > 详细

spring学习--4

时间:2016-04-04 12:59:03      阅读:265      评论:0      收藏:0      [点我收藏+]
参考书籍《spring in action》
 
1. AOP
before you wak the walk, you have to learn to walk the walk.
技术分享
1) advice---the job of an aspect (what and when)
/before
/after
/after-returning
/after throwing
/around: beforen and after
2) join points---a point in the execution of the application where an aspect can be plugged in.
3)pointcuts---where the advice should be woven
技术分享
4)aspects--- advice & joincuts
5)introduction---add new methods or attributes to existing classes.
6)weaving---the process of applyng aspects to target object to create a
 new proxied object.
/compile time
/class load time
/runtime
2. spring 对AOP的支持方式
1)classic spring proxy-based AOP
技术分享
2)pure-POJO aspects
3) @AspectJ annotation driven aspects.
4) injected AspectJ aspects.
 
3.creating aspect in spring
1)selecting join points with pointcuts.
eg:
execution(* concert.Performance.perform())
and bean(‘woodstock‘)
技术分享
2) creating annotated aspects
@Aspect
public class Audience {
@Pointcut("execution(** concert.Performance.perform(..))")
public void performance() {}
@Before("performance()")
public void silenceCellPhones() {
System.out.println("Silencing cell phones");
}
@Before("performance()")
public void takeSeats() {
System.out.println("Taking seats");
}
@AfterReturning("performance()")
public void applause() {
System.out.println("CLAP CLAP CLAP!!!");
}
@AfterThrowing("performance()")
public void demandRefund() {
System.out.println("Demanding a refund");
}
}

配置:

@Configuration
@EnableAspectJAutoProxy
@ComponentScan
public class ConcertConfig {
@Bean
public Audience audience() {
return new Audience();
}
}

3)handling params in advice

 

技术分享

4) annotation introductions

dynamic language like ruby and groovy can add new methods to an object or class.

技术分享

 
 

spring学习--4

原文:http://www.cnblogs.com/flyingbee6/p/5351676.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!