spring2.0_aop配置

 

xml文件配置

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.     xmlns:aop="http://www.springframework.org/schema/aop"
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans 
  6.     http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
  7.     http://www.springframework.org/schema/aop 
  8.     http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
  9.     <bean id="logAdvice" class="cn.com.y234.zteam.tool.aop.LogAdvice" />
  10.     <aop:config>
  11.         <aop:aspect id="logBefore" ref="logAdvice">
  12.             <aop:before
  13.                 pointcut="execution(* cn.com.y234.zteam.biz.IEmployeeBiz.*(..))"
  14.                 method="before" />
  15.             <aop:after-returning
  16.                 pointcut="execution(* cn.com.y234.zteam.biz.IEmployeeBiz.*(..))"
  17.                 method="afterReturning" />
  18.             <aop:after-throwing
  19.                 pointcut="execution(* cn.com.y234.zteam.biz.IEmployeeBiz.*(..))"
  20.                 throwing="throwable" method="afterThrowing" />
  21.             <aop:around
  22.                 pointcut="execution(* cn.com.y234.zteam.biz.IEmployeeBiz.*(..))"
  23.                 method="around" />
  24.         </aop:aspect>
  25.     </aop:config>
  26. </beans>

advice配置

 

  1. package cn.com.y234.zteam.tool.aop;
  2. import java.text.DateFormat;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Arrays;
  5. import java.util.Date;
  6. import org.apache.log4j.Logger;
  7. import org.aspectj.lang.JoinPoint;
  8. import org.aspectj.lang.ProceedingJoinPoint;
  9. public class LogAdvice {
  10.     private static Logger logger = Logger.getLogger(LogAdvice.class);
  11.     private static DateFormat sdf = new SimpleDateFormat(
  12.             "yyyy年MM月dd日 hh时mm分ss秒");
  13.      //前置通知
  14.     public void before(JoinPoint joinPoint) throws Throwable {
  15.         logger.info("前[系统日志][" + sdf.format(new Date()) + "]"
  16.                 + joinPoint.getTarget() + "("
  17.                 + Arrays.toString(joinPoint.getArgs()) + ")");
  18.     }
  19.      //后置通知
  20.     public void afterReturning(JoinPoint joinPoint) throws Throwable {
  21.         logger.info("后[系统日志][" + sdf.format(new Date()) + "]"
  22.                 + joinPoint.getTarget() + "("
  23.                 + Arrays.toString(joinPoint.getArgs()) + ")");
  24.     }
  25.      //环绕通知
  26.     public void around(ProceedingJoinPoint joinPoint) throws Throwable {
  27.         logger.info("环绕[系统日志][" + sdf.format(new Date()) + "]"
  28.                 + joinPoint.getTarget() + "("
  29.                 + Arrays.toString(joinPoint.getArgs()) + ")");
  30.     }
  31.      //异常通知
  32.     public void afterThrowing(JoinPoint joinPoint, Throwable throwable)
  33.             throws Throwable {
  34.         logger.info("异常[系统日志][" + sdf.format(new Date()) + "]"
  35.                 + joinPoint.getTarget() + "("
  36.                 + Arrays.toString(joinPoint.getArgs()) + ")");
  37.     }
  38. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值