使用注解进行实现:减少xml文件的配置。
1 建立切面类
不需要实现任何特定接口,按照需要自己定义通知。
package org.guangsoft.utils;
import java.util.Date;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
/***
* 定义用户的切面类
* ***/
@Component
@Aspect
public class UsersAdvice
{
// 前置的通知
@Before("execution(* com.bjsxt.service.impl.*.*(..))")
public void before()
{
System.out.println("before-------------" + new Date());
}
// 后置通知
// @After("execution(* com.bjsxt.service.impl.*.*(..))")
@AfterReturning(pointcut = "execution(* com.bjsxt.service.impl.*.*(..))", returning = "rv")
public vo