spring aop注意事项
来源:互联网 发布:金山软件港股行情 编辑:程序博客网 时间:2024/04/28 00:15
spring aop有 JDK动态代理及CGLIB,还可以使用ASPECTJ。
其JDK动态代理是对接口代理,而cglib是对类进行代理。aspectJ则对源代码class进行织入。
这里需要注意的是cglib代理,它会调用两次目标对象的构造方法。JDK动态代理及aspectJ则只调用一次。
这样当使用cglib代理,并且使用目标对象的默认无参构造方法进行一些资源初始化时,可能就会发生初始化两次(根据业务场景,假设只能初始化一次)。
测试代码:
xml中配置aop:
<aop:config proxy-target-class="true">
<aop:aspect ref="loggerAspect">
<aop:pointcut expression="execution(* test.spring..*.*(..))"
id="loggerPointcutOfService" />
<aop:before method="log" pointcut-ref="loggerPointcutOfService" />
<aop:after method="afterLog" pointcut-ref="loggerPointcutOfService" />
<aop:around method="logTimeForMethodSpend" pointcut-ref="loggerPointcutOfService" />
</aop:aspect>
</aop:config>
<bean id="b" class="test.spring.B">
</bean>
在B类构造方法中,输出:
in b construtor
调用代码对象b的相应方法时:
会输出:
in b construtor
in b construtor
- spring aop注意事项
- Spring AOP jar包注意事项
- final方法在Spring AOP中的注意事项
- Spring Aop拦截controller配置注意事项
- 接口实现时Spring AOP切入点注意事项
- Spring AOP日志配置以及注意事项
- Spring JDBC-实施Spring AOP事务注意事项及案例分析
- spring开发中加了aop配置标签需注意事项
- 类继承/接口实现时Spring AOP切入点注意事项
- spring中applicationContext中配置aop的注意事项
- AOP、Spring的AOP
- AOP--Spring AOP
- Spring AOP 嵌套AOP
- spring AOP
- Spring AOP
- Spring AOP
- spring aop
- Spring AOP
- 用C#生成不重复的随机数
- Mongodb与spring集成
- 未在本地计算机上注册Microsoft.ACE.OLEDB.12.0提供程序
- IP地址
- JQuery Easyui做异步删除
- spring aop注意事项
- android gallery笔记
- A20启动代码流程分析
- java环境变量配置方法
- 人生如泡沫
- JAVA Socket超时浅析
- Android照片墙应用实现,再多的图片也不怕崩溃
- Swift UI控件 --> UITableView
- Windows vs Linux