基于xml配置
1.导包
spring-context
spring-test
junit
mysql
aspectweaver
2.bean.xml中
aop约束
dao对象
service对象
datasource对象
transactionManager对象
配置aop
基于注解的aop配置
在bean.xml中放入context约束
写上要扫描的包context-scan package=""
开启aop注解支持
<aop:aspect-autoproxy>
在dao service 上面写上对应的注解@Service @Respository
在Service中引用dao @Autowired
在测试中引用service @Autowired
其他类上写@Componet注入容器
在切面类上写@Aspect
在切面类中写切入点表达式
@Pointcut("execution(* com.itheima.service.impl.*>*(..))")
public void pointcut1(){}
在通知方法上写对应的注解
前置@Before("pt1()") 提交后置@AfterReturing("pt1()")
回滚 异常通知@AfterThrowing("pt1()")
释放 最终通知@After("pt1()") 环绕通知@Around("pt1()")
测试类
@RunWith(SpringJunit4ClassRunner.class)
@ContextConfiguration(locations="classpath:bean.xml")
引用service @Autowired
测试函数上加@Test