JOBS4TIMES jobs4timesLogo

Working with Spring Pointcut and Advisors

Agenda :
  1. Introduction to Spring Framework

Types of Pointcuts

  1. Static Pointcut
  2. Dynamic Pointcut

Static Pointcut

NameMatchMethodPointcut :

mybeans.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:p="http://www.springframework.org/schema/p"
 xsi:schemaLocation="http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="accdao" class="com.pointcut.AccountDAOTestImpl"/>
  
<bean id="accServices" class="com.pointcut.AccountServicesImpl">
 <constructor-arg>
  <ref local="accdao"/>
 </constructor-arg>
</bean>

<bean id="logging" class="com.pointcut.LoggingAdvice"/>

<bean id="mypointcut" 
  class="org.springframework.aop.support.NameMatchMethodPointcut">
 <property name="mappedName">
  <value>withdraw</value>
 </property>
</bean>

<bean id="loggingAdvisor" 
  class="org.springframework.aop.support.DefaultPointcutAdvisor">
 <property name="advice">
  <ref local="logging"/>
 </property>
 <property name="pointcut">
  <ref local="mypointcut"/>
 </property>
</bean>

<bean id="accountServices" 
   class="org.springframework.aop.framework.ProxyFactoryBean">
 <property name="targetName" value="accServices"/>
 <property name="interceptorNames">
  <list>
   <value>loggingAdvisor</value>
  </list>
 </property>
</bean>

</beans>
Regular Expression Method Pointcut :
<bean id="mypointcut" 
  class="org.springframework.aop.support.JdkRegexpMethodPointcut">
 <property name="patterns">
  <list>
   <value>.*get.*</value>
   <value>.*set.*</value>
  </list>
 /property>
</bean>

Dynamic Pointcuts

Control Flow Pointcut :
<bean id="mypointcut" 
  class="org.springframework.aop.support.ControlFlowPointcut">
 <constructor-arg>
  <value>com.aop.WithDrawService</value>
 </constructor-arg>
</bean>

BACK