1.在springMvc的xml配置文件中加入开启aop和扫描aop的配置
<!-- 将类加入IOC容器 --> <context:component-scan base-package="com.huqi.aop"></context:component-scan> <!-- 开启aop注解 --> <aop:aspectj-autoproxy/>
2.编写aop类
@Aspect @Configuration public class Logger { @Pointcut("@within(org.springframework.stereotype.Controller) || @within(org.springframework.web.bind.annotation.RestController)") public void cutController() { } @Around("cutController()") public Object recordSysLog(ProceedingJoinPoint joinPoint) throws Throwable { try { ob = joinPoint.proceed(); } catch (Throwable throwable) { //此处一定要抛出异常 throw throwable; } finally { } return ob; } }