spring mvc 模式下AOP切面controller層例子spring
@Aspectapi
@Componentmvc
public class MyAop {app
@Autowiredide
private HttpServletRequest request;測試
public MyAop() {spa
}代理
@AfterReturning(value="execution(* com.che.api.controller..*.*(..))",returning="returnValue")xml
public void beforeOperationLog(JoinPoint point, Object returnValue) {it
System.out.println("---------beforeOperationLog-------");
}
@AfterThrowing(pointcut="execution(* com.che.api.controller..*.*(..))", throwing="ex")
public void afterThrow(JoinPoint joinPoint, Exception ex){
System.out.println("---------afterThrow-------");
}
}
在 applicationcontext.xml裏註冊AOP註解代理:<aop:aspectj-autoproxy expose-proxy="true"/> cglib代理
測試(spring mvc的controller,service,dao這類的配置就不說了)