以前都是使用xml声明式事务,一些之前不了解的可以不认识怎么配置,而且一下子也不好理解,那我们可以整合 aspects 进行注解式事务处理
maven 引入包:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.10</version>
</dependency>
application.xml 增加配置(注意AOP注解类一定要被扫描到,要在 component scan 里面扫描得到)
<aop:aspectj-autoproxy/>
简单demo示例:
@Component
@Aspect
public class TestAnnotitaionAop{
@Pointcut("execution(* com.kds2.service.*.*(..))")
public void point() {
}
@Before("point()")
public void doBefore() {
System.out.println("执行方法前");
}
@After("point()")
public void doAfter() {
System.out.println("执行方法后");
}
}