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>