AOP - Aspect Oriented Programing,面向切面编程。将封装好的对象切开,找出其中对多个对象产生影响的公共行为,并将其封装为一个可重用的模块,这个模块被命名为“切面”,切面将那些与业务无关,却被业务模块共同调用的逻辑提取并封装起来,减小了系统中的重复代码,下降了模块间的耦合度,同时提升了系统的可维护性。spring
好比:将一大块包含复制业务逻辑的代码,经过横向抽取的方式抽取到一个个独立的模块中,好比拆分为业务逻辑、性能监控以及事务处理。express
Spring AOP在运行期间经过代理方式向目标类织入加强代码。编程
在Spring项目中配置的事务管理器,就使用到了Spring AOP。性能
<aop:config> <aop:pointcut id="bussinessService" expression="execution(public * com.honglin.service..*.*(..))" /> <aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="find*" read-only="true" /> <tx:method name="add*" propagation="REQUIRED"/> </tx:attributes> </tx:advice>
参考资料:spring AOP在实际项目中的应用spa