读书人

Spring Aop 简略例子

发布时间: 2012-08-22 09:50:34 作者: rapoo

Spring Aop 简单例子

bean.xml

package cn.nick.spring.Inetepor;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotation.Pointcut;import org.springframework.stereotype.Service;import org.springframework.util.StopWatch;@Aspect @Servicepublic class MyInetepor {@Pointcut("execution(* cn.nick.spring..*.*(..))")private void anyOldTransfer(){}// 这是一个切入点@Before("anyOldTransfer()")public void doAccessCheck() {System.out.println("第一个切面练习!");}//环绕消息@Around("anyOldTransfer()")    public Object profile(ProceedingJoinPoint pjp) throws Throwable {        StopWatch sw = new StopWatch(getClass().getSimpleName());        try {            sw.start(pjp.getSignature().getName());            return pjp.proceed();        } finally {            sw.stop();            System.out.println(sw.prettyPrint());        }    }}


读书人网 >Web前端

热点推荐