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()); } }}