Spring AOP

前端之家收集整理的这篇文章主要介绍了Spring AOP前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Spring-mybatis.xml

<aop:aspectj-autoproxy />

LogAdvice.java

@Aspect
@Component
public class LogAdvice {

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

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

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

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

    @Around("method()"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</artifactId>aspectjweaverversion>1.8.7>
>

 

猜你在找的Spring相关文章