Spring 切面 AOP基础 之二
2015-05-03 21:36
281 查看
锋利的AOP,上回说到我们利用AOP对服务进行了代理,切的很亮,很光滑,我想吟一手,快拦住我。莫道男儿心如铁,君不见,满川红叶,尽是离人眼中血。
对于AOP还应该罅隙的解释一下,切面的功能被称为通知Advice。通知:描述切面要完成的工作,确定何时何地执行。
连接点(Joinpint):程序执行中能够插入切面的一个时机,可以是方法被调用时,异常抛出时,切面代码通过这个点插入到程序的一般流程中。
切入点(Pointcut):切入点可以缩小切面通知的连接点的范围。相当于切入点定义了“何地”,通常使用明确的类和方法名称,或者利用正则匹配类和方法的名称模板。
切面(Aspect):切面是通知和切入点的结合。
接上文的例子,这次使用Pointcut来使用AOP:
spring配置文件:Spring-Custom.xml
这样就利用了切入点定义了包含URL的路径才会被执行通知。
对于AOP还应该罅隙的解释一下,切面的功能被称为通知Advice。通知:描述切面要完成的工作,确定何时何地执行。
连接点(Joinpint):程序执行中能够插入切面的一个时机,可以是方法被调用时,异常抛出时,切面代码通过这个点插入到程序的一般流程中。
切入点(Pointcut):切入点可以缩小切面通知的连接点的范围。相当于切入点定义了“何地”,通常使用明确的类和方法名称,或者利用正则匹配类和方法的名称模板。
切面(Aspect):切面是通知和切入点的结合。
接上文的例子,这次使用Pointcut来使用AOP:
spring配置文件:Spring-Custom.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="customerService" class="com.mkyong.customer.services.CustomerService" > <property name="name" value="Yong Mook Kim" /> <property name="url" value="http://www.mkyong.com" /> </bean> <bean id="hijackAroundMethodBeanAdvice" class="com.mkyong.aop.HijackAroundMethod" /> <!--代理类,代理Service同时注入AOP的切点 --> <bean id="customerServiceProxy" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="target" ref="customerService" /> <property name="interceptorNames"> <list> <value>customerAdvisor</value> </list> </property> </bean> <!--<bean id="customerAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor"> <property name="mappedName" value="printName" /> <property name="advice" ref="hijackAroundMethodBeanAdvice" /> </bean>--> <!--通知接入点 --> <bean id="customerAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <property name="patterns"> <list> <value>.*URL.*</value> </list> </property> <property name="advice" ref="hijackAroundMethodBeanAdvice" /> </bean> </beans>
这样就利用了切入点定义了包含URL的路径才会被执行通知。
相关文章推荐
- spring aop切面编程基础实例
- Spring 切面 AOP基础 之三
- Spring AOP切面基础 实现请求参数的验证
- 【Spring in Action】Spring的AOP基础知识及切面运用
- Spring详解之二:AOP(面向切面)
- 0047 Spring的AOP入门基础--切面组件--通知--切入点
- Spring基础配置(AOP切面编程)
- Spring 切面 AOP基础 之一
- Spring 切面 AOP基础 之四
- JavaEE框架——Spring入门基础(控制反转Ioc和切面技术Aop)
- 【spring aop切面】基础使用教程
- 【我看Spring】从一个简单的AOP示例看切面编程
- Spring AOP基础知识
- Spring中的AOP基础
- 重新学习之spring第二个程序,配置AOP面向切面编程
- 使用Spring进行面向切面(AOP)编程
- spring aop 如何切面到mvc 的controller
- Spring基础系列-AOP源码分析
- spring(基础11) Spring AOP 实现原理
- spring 第10 天 AOP 面向切面