Around增强处理

Around增强处理是一种功能比较强大的增强处理,近似于Before和AfterReturning增强处理的总和.Aound增强处理既可以在执行目标方法之前织入增强工作,也可以在执行目标之后织入增强工作

当定义一个Around增强处理方法时,该方法的第一个参数必须是ProceedingjoinPoint类型(至少包含一个形参,在增强的方法体内,调用ProceedingjoinPoint的proceed()方法才会执行目标方法,如果程序没有调用这个方法,则目标方法不会被执行

public interface IUserDao {
	public void save();
	public void update();
	public void delete();
}
@Repository
public class UserDaoIm implements IUserDao{

	public void save() {
		System.out.println("保存用户信息");
	}

	public void update() {
		System.out.println("更新用户信息");
	}

	public void delete() {
		System.out.println("删除用户信息");
	}
	
}
 
@Aspect
public class Advice {
	@Around("execution(* save(..))")
	public void adviceMethod(ProceedingJoinPoint point) throws Throwable{
		System.out.println("开始事务提交");
		point.proceed();	
	}
}
<description>SpringIOC-初始 </description>
	<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
	<context:component-scan base-package="annotation.**"></context:component-scan>
	<bean id="advice" class="annotation.Advice"></bean>
<!-- 	<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"></bean> -->
public static void main(String[] args) {
		ApplicationContext context=new ClassPathXmlApplicationContext("annotation/beam.xml");
		//获取代理lei
		IUserDao userDao=(IUserDao)context.getBean("userDaoIm");
		userDao.save();
	}

猜你喜欢

转载自201407105131.iteye.com/blog/2204963
今日推荐