日期:2014-05-17 浏览次数:20864 次
<aop:aspectj-autoproxy/>
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @Aspect public class AOPServiceLogger { public static final String ServiceEDP = "execution( * org.aaa.bbb.service.implement..*.*(..))"; public static final String DAOEDP = "execution( * org.aaa.bbb.dao.hibernate..*.*(..))"; private SRLogger log = SRLogger.getLogger(AOPServiceLogger.class); @Around(ServiceEDP) // spring中Around通知 public Object logAround(ProceedingJoinPoint joinPoint) { log.info("Enter Service method : " + joinPoint.getSignature().getName() + " in class " +joinPoint.getTarget()); Object[] args = joinPoint.getArgs(); Object obj = null; try { obj = joinPoint.proceed(args); } catch (Throwable e) { log.error(e); e.printStackTrace(); } log.info("Exit Service method : " + joinPoint.getSignature().getName() + " in class " +joinPoint.getTarget()); return obj; } @Around(DAOEDP) // spring中Around通知 public Object logAroundDAO(ProceedingJoinPoint joinPoint) { log.info("Enter DAO method : " + joinPoint.getSignature().getName() + " in class " +joinPoint.getTarget()); Object[] args = joinPoint.getArgs(); Object obj = null; try { obj = joinPoint.proceed(args); } catch (Throwable e) { log.error(e); e.printStackTrace(); } log.info("Exit DAO method : " + joinPoint.getSignature().getName() + " in class " +joinPoint.getTarget()); return obj; } }