`
tanglei198577
  • 浏览: 60572 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

Spring AOP config file and explaination

    博客分类:
  • SSH
阅读更多

I have give the comment in xml file:

<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" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation=" 
	http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
	http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-2.5.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> 
    
   <description>Quick AOP Start for Spring</description>
    <!-- AOP of audience -->
    
    <!-- DefaultPointcutAdvisor bean -->
    <bean id="audienceAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
         <!-- both values of advice below equivalent,one method implements MethodInterceptor,another method is implements MethodBeforeAdvice,AfterReturningAdvice,ThrowsAdvice,annotate one of them--> 
         <!--<property name="advice" ref="AudienceAroundAdvice"></property>-->
         <property name="advice" ref="AudienceAdvice"></property> 
         <!-- define point cut of advisor ,one is aspectJ pointcut,another is regular pointcut,annotate one of them-->
         <!--<property name="pointcut" ref="PerformencePointcutAspectJ"></property>-->
         <property name="pointcut" ref="PerformencePointcut"></property>
    </bean>
    
    <!-- AspectJExpressionPointcutAdvisor bean -->
    <bean id="audienceAdvisorAspectJ" class="org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor">
         <!--<property name="advice" ref="AudienceAroundAdvice"></property>-->
         <property name="advice" ref="AudienceAdvice"></property> 
         <!-- define expression of advisor -->
         <property name="expression" value="execution(* *.perform(..))"></property>
    </bean>
    
    <!-- create advice of audience by implements MethodBeforeAdvice,AfterReturningAdvice,ThrowsAdvice-->
    <bean id="AudienceAdvice" class="com.spring.aop.AudienceAdvice">
         <property name="audience" ref="audience"></property>
    </bean>
    <!-- create around advice of audience by implements MethodInterceptor-->
    <bean id="AudienceAroundAdvice" class="com.spring.aop.AudienceAroundAdvice">
         <property name="audience" ref="audience"></property>
    </bean>
    
    <!-- audience bean -->
    <bean id="audience" class="com.spring.aop.Audience"></bean>  
    <!-- regular pointcut-->
    <bean id="PerformencePointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut">
         <property name="pattern" value=".*perform"></property>  
    </bean>
    <!-- AspectJ pointcut-->
    <bean id="PerformencePointcutAspectJ" class="org.springframework.aop.aspectj.AspectJExpressionPointcut">
         <property name="expression" value="execution(* *.perform(..))"></property>  
    </bean>
    

   <!-- parent base proxyBean ,it is convenient to extends-->
   <bean id="advisorBase" class="org.springframework.aop.framework.ProxyFactoryBean" abstract="true"> 
     <!-- both values of interceptorNames below equivalent,one method is using AspectJ,another method 
     is classic spring proxy-based AOP,annotate one of them--> 
     <!-- <property name="interceptorNames" value="audienceAdvisorAspectJ"></property> -->
     <property name="interceptorNames" value="audienceAdvisor"></property>
     <!-- proxy interface-->
     <property name="proxyInterfaces" value="com.performence.Performer"></property>
   </bean>
    
   <!-- inherit from advisorBase -->
   <bean id="duke" parent="advisorBase">
     <!-- target of ProxyFactoryBean -->
     <property name="target" ref="dukeTarget"></property>
   </bean>
   <bean id="dukeTarget" class="com.performence.PoeticJuggler" >
      <constructor-arg ref="poem"/>
      <property name="song" value="Without U" /> 
   </bean>
   <bean id="poem" class="com.performence.LovePoem" ></bean>
   
   <!-- inherit from advisorBase -->
   <bean id="stevie" parent="advisorBase">
     <property name="target" ref="stevieTarget"></property>
   </bean>
   <bean id="stevieTarget" class="com.performence.PoeticJuggler" >
      <constructor-arg ref="poem"/>
      <property name="song" value="Lady GaGa" /> 
   </bean>
   
   </beans>

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics