spring mvc 模式下AOP切面controller层例子

@Aspect

@Component

public class MyAop {


@Autowired

private HttpServletRequest request;

public MyAop() {

}

@AfterReturning(value="execution(* com.che.api.controller..*.*(..))",returning="returnValue")

public void beforeOperationLog(JoinPoint point, Object returnValue) {

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这类的配置就不说了)