@Aspect 注解拦截器

@Aspect
@Component
public class ServiceMonitor {

	
	@Pointcut("execution(* sample..*Service.*(..))")
    public void recordLog(){}
	
	
    @Around("recordLog()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable{
    	Object obj;
    	System.out.println("已经记录下操作日志@Around 方法执行前");
    	obj = pjp.proceed();
        System.out.println("已经记录下操作日志@Around 方法执行后");
        return obj;
    }
	
	@AfterReturning("recordLog()")
	public void logServiceAccess(JoinPoint joinPoint) {
		
		System.out.println("Completed: " + joinPoint);
	}
	
	@Before("recordLog()")
	public void logServiceAcces1(JoinPoint joinPoint) {
		System.out.println("start: " + joinPoint);
	}
	
	@After("recordLog()")
	public void logServiceAcces2(JoinPoint joinPoint) {
		System.out.println("After: " + joinPoint);
	}

}

猜你喜欢

转载自gangling.iteye.com/blog/2369069