创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!
AOP核心概念
1、横切关注点
对哪些方法进行拦截,拦截后怎么处理,这些关注点称之为横切关注点
2、切面(aspect)
类是对物体特征的抽象,切面就是对横切关注点的抽象
3、连接点(joinpoint)
被拦截到的点,因为spring只支持方法类型的连接点,所以在Spring中连接点指的就是被拦截到的方法,实际上连接点还可以是字段或者构造器
4、切入点(pointcut)
对连接点进行拦截的定义
5、通知(advice)
所谓通知指的就是指拦截到连接点之后要执行的代码,通知分为前置、后置、异常、最终、环绕通知五类
6、目标对象
代理的目标对象
7、织入(weave)
将切面应用到目标对象并导致代理对象创建的过程
8、引入(introduction)
在不修改代码的前提下,引入可以在运行期为类动态地添加一些方法或字段
Spring 实现AOP所需要的包:
1、Spring提供的jar包
2、aopalliance.jar
3、aspectjweaver.jar
Spring 实现AOP的方式:
1、Java动态代理
该方法针对接口的实例创建代理
applicationContext.xml的配置如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd"> <bean id="concreteImplementor" class="com.marving.aop.ConcreteImplementor" /> <bean id="interceptorHandler" class="com.marving.aop.InterceptorHandler" /> <aop:config> <aop:aspect id="interceptor" ref="interceptorHandler"> <aop:pointcut id="addAllMethod" expression="execution(* com.marving.aop.Abstration.*(..))" /> <aop:before method="doSomething" pointcut-ref="addAllMethod" /> <aop:after method="doSomething" pointcut-ref="addAllMethod" /> </aop:aspect> </aop:config> </beans>
文章标题:SpringAOP的几种实现方式总结-创新互联
标题链接:https://www.cdcxhl.com/article40/pjseo.html
成都网站建设公司_创新互联,为您提供微信小程序、品牌网站建设、网站制作、自适应网站、服务器托管、网站设计公司
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联