一、aop 思想介绍
- 横向重复,纵向抽取 filter

- 动态代理

- interceptor中

二、spring中的aop概念
- 封装了动态代理技术.来体现aop.

三、spring实现aop的原理
-
动态代理(有接口的话优先使用动态代理)
被代理对象必须要实现接口,才能产生代理对象。如果没有接口将不能使用动态代理技术 -
cglib代理(没有接口)
第三方代理技术,cglib代理.可以对任何类生成代理,代理的原理是对目标对象进行继承代理。如果目标对象被final修饰,那么该类无法被cglib代理.
四、aop名词学习

五、spring中的aop演示
-
xml配置步骤
|--> 01.导包 4 + 2
spring的aop包:spring-aspects-4.2.4.RELEASE.jar + spring-aop-4.2.4.RELEASE.jar
spring需要第三方aop包:com.springsource.org.aopalliance-1.0.0.jar + com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
|--> 02.准备目标对象
|--> 03.准备通知
|--> 04.配置进行织入,将通知织入目标对象中
-
注解配置步骤
|--> 01.导包 4 + 2
spring的aop包:spring-aspects-4.2.4.RELEASE.jar + spring-aop-4.2.4.RELEASE.jar
spring需要第三方aop包:com.springsource.org.aopalliance-1.0.0.jar + com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
|--> 02.准备目标对象
|--> 03.准备通知
|--> 04.配置进行织入,将通知织入目标对象中


六、spring中aop事务
-
spring封装了事务管理代码
1)、事务操作:打开事务、提交事务、回滚事务
2)、事务操作对象(因为在不同平台,操作事务的代码各不相同.spring提供了一个接口)
|--> PlatformTransactionManager 接口
|-> DataSourceTransactionManager
|-> HibernateTransactionManager
|-> 注意:在spring中玩事务管理.最为核心的对象就是TransactionManager对象
|--> spring管理事务的属性介绍
|-> 事务的隔离级别
1 读未提交
2 读已提交
4 可重复读
8 串行化
|-> 是否只读 (true 只读 | false 可操作)
|-> 事务的传播行为
-
spring管理事务方式
1)、编码式(不常用)
01.将核心事务管理器配置到spring容器
02.配置TransactionTemplate模板
03.将事务模板注入Service
04.在Service中调用模板
2)、xml配置(aop)
|-> 01.导包 (aop | aspect | aop联盟 | weaving织入包)
|-> 02.导入新的约束(tx)

beans: 最基本、context:读取properties配置、aop:配置aop、tx:配置事务通知
|-> 03.配置通知

|-> 04.配置将通知织入目标

3)、注解配置(aop) ---> 非常重要
|-> 01.导包 (aop | aspect | aop联盟 | weaving织入包)
|-> 02.导入新的约束(tx)

beans: 最基本、context:读取properties配置、aop:配置aop、tx:配置事务通知
|-> 03.开启注解管理事务

|-> 04.使用注解


注解可以加在方法上,也可以抽取出来加在类上(若个别方法注解某些属性不同,还可以单独将注解加在方法上)
网友评论