您的位置:首页 > 编程语言 > Java开发

Spring AOP

2015-10-27 20:29 459 查看
Spring-mybatis.xml

<aop:aspectj-autoproxy />


LogAdvice.java

@Aspect
@Component
public class LogAdvice {

//可复用的植入点,方法名method为引用
@Pointcut("execution(* com.ssm..*.transferMoneyByProcedure(..))")
public void method() {}

@Before("execution(public void com.ssm.dao.UserDao.transferMoney(*))")
public void before(){
System.err.println("Spring AOP  before method....");
}

@AfterReturning("method()")
public void after() {
System.err.println("Spring AOP  after method....");
}

@AfterThrowing("method()")
public void exception() {
System.err.println("Spring AOP  throws Exception....");
}

@Around("method()")
public void around(ProceedingJoinPoint point) throws Throwable {

System.err.println("String AOP around start....");
point.proceed();
System.err.println("String AOP around end....");
}

}


pom.xml

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: