Pointcut is another core AOP concept, usually appearing as an expression, and allowing you to match certain program execution points to apply an advice. In classic Spring AOP, pointcuts are also declared as Spring beans by using pointcut classes.
Spring provides a family of pointcut classes for you to match program execution points. You can simply declare beans of these types in your bean configuration file to define pointcuts. However, if you find that the built-in pointcut classes cannot satisfy your needs, you can write your own by extending StaticMethodMatcherPointcut or DynamicMethodMatcherPointcut. The former matches execution points by the static class and method information only, while the latter matches them by the dynamic argument values as well.
How It Works:
we used all codes except of configuration file in previous article.
Method Name Pointcuts:
<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="arithmeticCalculator" class="cn.cgw.aop.ArithmeticCalculatorImpl"/>
<bean id="unitCalculator" class="cn.cgw.aop.UnitCalculatorImpl"/>
<!-- Advice -->
<bean id="loggingBeforeAdvice" class="cn.cgw.aop.LoggingBeforeAdvice"/>
<bean id="loggingAfterAdvice" class="cn.cgw.aop.LoggingAfterAdvice"/>
<bean id="loggingThrowsAdvice" class="cn.cgw.aop.LoggingThrowsAdvice"/>
<bean id="loggingAroundAdvice" class="cn.cgw.aop.LoggingAroundAdvice"/>
<!-- PointCut -->
<bean id="methodNamePointcut" class="org.springframework.aop.support.NameMatchMethodPointcut">
<property name="mappedNames">
<list>
<value>add</value>
<value>div</value>
</list>
</property>
</bean>
<!-- Advisor -->
<bean id="methodNameAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="pointcut" ref="methodNamePointcut"/>
<property name="advice" ref="loggingAroundAdvice"/>
</bean>
<!-- AOP Proxy -->
<bean id="arithmeticCalculatorProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<!--
<property name="proxyInterfaces">
<list>
<value>cn.cgw.aop.ArithmeticCalculator</value>
</list>
</property>
-->
<property name="target" ref="arithmeticCalculator"/>
<property name="interceptorNames">
<list>
<value>methodNameAdvisor</value>
</list>
</property>
</bean>
</beans>
Regular Expression Pointcuts:
<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="arithmeticCalculator" class="cn.cgw.aop.ArithmeticCalculatorImpl"/>
<bean id="unitCalculator" class="cn.cgw.aop.UnitCalculatorImpl"/>
<!-- Advice -->
<bean id="loggingBeforeAdvice" class="cn.cgw.aop.LoggingBeforeAdvice"/>
<bean id="loggingAfterAdvice" class="cn.cgw.aop.LoggingAfterAdvice"/>
<bean id="loggingThrowsAdvice" class="cn.cgw.aop.LoggingThrowsAdvice"/>
<bean id="loggingAroundAdvice" class="cn.cgw.aop.LoggingAroundAdvice"/>
<!-- Regular expression pointcut -->
<bean id="regexpAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="patterns">
<list>
<value>.*mul.*</value>
<value>.*div.*</value>
</list>
</property>
<property name="advice" ref="loggingAroundAdvice"/>
</bean>
<!-- AOP Proxy -->
<bean id="arithmeticCalculatorProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<!--
<property name="proxyInterfaces">
<list>
<value>cn.cgw.aop.ArithmeticCalculator</value>
</list>
</property>
-->
<property name="target" ref="arithmeticCalculator"/>
<property name="interceptorNames">
<list>
<value>regexpAdvisor</value>
</list>
</property>
</bean>
</beans>
分享到:
相关推荐
多模态图像匹配是指识别并对应两个或多个具有显著模态或非线性外观差异的图像中相同或相似的结构/内容,这在医学、遥感和计算机视觉等多种应用中是一个基础且关键的问题。近年来,尤其是在深度学习时代,因为多模态...
本文档《Matching with Shape Contexts.pdf》主要介绍了形状上下文(Shape Context)在图像匹配领域的应用,特别是如何利用形状上下文测量形状相似性以及恢复点对应关系。形状上下文作为一种新的形状描述符,能够...
本文介绍了一种名为“匹配追踪”(Matching Pursuit)的算法,该算法能够将任何信号分解为从冗余函数词典中选取的波形线性组合。这些波形被精心挑选以最佳匹配信号结构。匹配追踪是一种计算自适应信号表示的一般程序...
【标题】: "基于matlab粒子群图像稀疏分解 (matching pursuit with PSO optimization).rar" 这个标题揭示了我们讨论的主题是使用MATLAB编程环境,结合粒子群优化算法(PSO,Particle Swarm Optimization)来实现...
文章提出了一种名为SAIL1(String Matching with Wildcards and Length Constraints)的高效算法,该算法能在非线性时间内返回模式`P`在文本`T`中的每一次出现,并且只需要线性的额外空间。具体来说,对于长度为`n`...
标题《Object retrieval with large vocabularies and fast spatial matching》中包含的知识点涵盖了大规模图像检索技术的关键组成部分,具体可以展开如下: 1. 视觉词袋模型(Bag-of-Words, BoW):这是一个广泛...
《Stereo Matching with Color-Weighted Correlation, Hierarchical Belief Propagation, and Occlusion Handling》
在Spring MVC中,URL映射是一个关键功能,它负责将用户发起的URL请求与控制器类的方法进行关联。Spring MVC提供了多种映射策略,其中一种是基于Apache Ant风格的路径匹配器(AntPathMatcher),这使得URL映射更加...
射频基本有效阻抗匹配与ADS 讲义 中文版,PDF 实验1 匹配架构设计(Smith Chart Wizard) • 实验2 替换真实组件与有损传输线(CILD) • 实验3 匹配电路优化 • 实验4 汇入 Layout 档案 • 实验5 EM + Component ...
标题《调和对象的全面模式匹配》表明这篇文章主要探讨了函数式语言中重要的模式匹配特性如何与面向对象语言中的数据抽象和扩展性进行整合。文章指出,尽管模式匹配是现代函数式编程语言的重要特性,但它与面向对象...
with fewer changes to the cover image. The experimental results of the proposed method show better performance than traditional LSBmatchingintermsofdistortionandresistanceagainstexisting ...
4. Working with Spring Boot 5. Learning about Spring Boot Features 6. Moving to Production 7. Advanced Topics II. Getting Started 8. Introducing Spring Boot 9. System Requirements 9.1. Servlet ...
ST-Matching算法 java实现
在IT领域,特别是计算机科学与算法研究中,字符串匹配是一个重要的课题,而使用有限自动机(Finite Automata,简称FA)进行字符串匹配则是一种高效且经典的方法。这种方法不仅被广泛应用于文本搜索、编译器设计、...
多接入技术参数辅助的射频模式匹配定位技术性能研究,李伊婕,崔杰,本文提出了一种新的定位方法--射频模式匹配(RFPM),也被称为指纹,是第三代合作伙伴计划(3GPP)RAN4会议提出的一种定位技术。...
figure matching figure matching figure matching figure matching figure matching figure matching figure matching figure matching
Stereo matching algorithm with guided filter and modified dynamic programming
射频阻抗匹配是射频电路设计中的一个重要概念,它主要涉及使射频源和负载之间阻抗匹配,从而优化功率传输效率。阻抗(Impedance)是一个通用术语,它应用于任何阻碍电流流动的电路特性。阻抗概念最早由电磁理论的...
以及Pattern Matching for `instanceof`,提高了类型检查的可读性。 2. **Spring Boot 3**: Spring Boot 3尚未正式发布,但我们可以期待它在简化Spring应用程序启动和配置方面进一步提升。通常,Spring Boot包含...