Spring AOP实现用户操作日志管理

通过注解方式使用AOP实现用户操纵日志管理的具体步骤如下:
1、在spring配置文件加入支持@AspectJ标记,如下:
<aop:aspectj-autoproxy/>

2、配置一个日志操作bean,可以像普通bean一样注解以便spring管理,但是要加上@Aspect以便Spring将他作为切面累搜索到,如下:
@Aspect
@Component("logAspect")
public class LogAspect extends BaseAction{
/**
*
*/
}

3、定义切入点和方法
@Pointcut("execution(* *.*.*.service..*.add*(..)) || execution(* *.*.*.service..*.modify*(..)) ")
public void insertPointcut() {
/**
*
*/
}

4、在具体处理方法上添加建议
@Before("insertPointcut()")
public void saveLog(JoinPoint joinPoint)
throws Exception{
/**
*
*/   
}
OK,到这一步,service子包中的所有类的所有以add和modify方法被调用时,都会调用日志处理方法saveLog。

猜你喜欢

转载自jxdiamond.iteye.com/blog/1823707
今日推荐