Spring AOP

<context:component-scan base-package="com.seki.aop" />
<aop:aspectj-autoproxy/>


@Service
public class Performer {
	public void perform(String s1, String s2){
		System.out.println("------wait aop------");
	}
}


@Component
@Aspect
public class Audience {
	@Pointcut("execution(* com.seki.service.Performer.perform(..))&& args(s1,s2)")
	public void performance(String s1,String s2){}
	
	@Around("performance(s1,s2)")
	public void watchPerformance(ProceedingJoinPoint joinPoint,String s1,String s2){
		try {
			System.out.println("------begin aop-----");
			Object obj[] = joinPoint.getArgs();
			  for(Object o :obj){
			   System.out.println(o);
			  }
			 System.out.println(s1);
			 System.out.println(s2);
			joinPoint.proceed();
			System.out.println("------end aop-----");
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}

}

你可能感兴趣的:(spring aop)