首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

spring3-基于诠注的AOP

2013-08-06 
spring3-基于注解的AOP要点:1.aop的概念真的很多。。。其实从使用出发无非两点:1,定义要拦截的方法,2,实现拦

spring3-基于注解的AOP

要点:

1.aop的概念真的很多。。。其实从使用出发无非两点:1,定义要拦截的方法,2,实现拦截后的操作方法。

?

2.基于注解的@Aspect需要配合bean声明来用,不然不报错,不执行。。官方doc貌似没提倒。

?

3. 注入的bean对象,访问其属性需要生成get/set方法, 如果直接访问也会出现空指针。

@Component@Aspectpublic class ServiceAdvice {Logger log = Logger.getLogger(ServiceAdvice.class);/** * 统一的函数耗时统计;返回结果打印 * @param pjp * @return * @throws Throwable */@Around("execution(* com.xx.service.*.*(..))")public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {// start stopwatchStopWatch watch = new StopWatch(pjp.toShortString());watch.start();Object retVal = pjp.proceed();watch.stop();log.info("#####  return #######"+LoggerHelper.ObjectComposer(retVal));log.info("#####  StopWatch #######"+watch.shortSummary());return retVal;}}

?

?

?

?

参考资料:

1.http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/aop.html? 官方doc,永远最有用

2.http://sishuok.com/forum/blogPost/list/2472.htmlAOP 之 6.5 AspectJ切入点语法详解? 最详细的aop表达式说明。

热点排行