首先要在springmvc的配置里面配置:
<!-- 启用spring对AspectJ注解的支持 -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 把切面类交由Spring容器来管理 -->
<bean id="logAspectBean" class="com.ssz.aspectj.LogAnnotationAspect"/>
<!-- 用户服务对象 -->
<context:annotation-config/>
然后写一个LogAnnotationAspect类:
package com.ssz.aspectj;
import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
/**
* 日志切面类
*/
@Component // 注入依赖
@Aspect // 定义切面类
public class LogAnnotationAspect {
private final static Logger logger = Logger.getLogger(LogAnnotationAspect.class);
@Suppre