Results 1 to 9 of 9

Thread: Advice called multiple times when using AttributeMatchMethodPointCut

  1. #1
    Join Date
    Mar 2009
    Posts
    116

    Default Advice called multiple times when using AttributeMatchMethodPointCut

    Hi,

    I'm trying to use Attribute pointcut in order to apply my aroundAdvice to only the functions in my service which are decorated with a [SessionScope] attribute.

    Since I've done that, the code goes in the aroundAdvice 3 times before it goes into the invoked method ! If I don't use the pointcut, the aroundAdvice is only hit once before the invoked method executes and returns fine.

    Am I doing something wrong ?


    here's my xml :

    HTML Code:
     <object id="pointCut" type="Spring.Aop.Support.DefaultPointcutAdvisor, Spring.Aop" >
        <property name="Pointcut">
          <object type="Spring.Aop.Support.AttributeMatchMethodPointcut, Spring.Aop">
            <property name="Attribute" value="Metrica.SpringExtension.SessionScopeEx.SessionScopeAttribute, Metrica.SpringExtension"/>
          </object>
        </property>
        <property name="advice" ref="aroundAdvice" />           
      </object>
    
      <object id="aroundAdvice" 
              type="Metrica.Service.Aspects.MetricaServiceAroundAdvice, Metrica.Service" />    
      
      <object id="metricaService" type="Spring.Aop.Framework.ProxyFactoryObject">
        <property name="Target">
          <!-- The Metrica service object which is injected all the necessary DAO's. -->
          <object type="Metrica.Service.MetricaService, Metrica.Service" singleton="true">
            <property name="myDatabaseDao" ref="DatabaseDao" />
          </object>
        </property>
        <property name="InterceptorNames">
          <list>        
            <value>aroundAdvice</value>
          </list>
        </property>    
      </object>

  2. #2
    Join Date
    Jul 2006
    Location
    Vienna
    Posts
    8

    Default same problem a bit different config

    I had the same problem and now have a similar problem also with a spring config using "DefaultAdvisorAutoProxyCreator"

    Code:
    <!-- protocol advisor -->
      <object id="protocolAdvisor" type="Spring.Aop.Support.AttributeMatchMethodPointcutAdvisor, Spring.Aop">
        <property name="Advice">
          <object type="CN.Core.Aspects.ProtocolAdvice, CN.Core" />
        </property>
        <property name="Attribute"
                  value="CN.Core.Aspects.ProtocolAttribute, CN.Core" />
      </object>
    
      <!-- AutoProxy definition -->
      <object type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator, Spring.Aop" />
    after changing the config to that, the advice is executed two instead of three times. What confuses me, is the fact, that the target of the first call is a CompositionAopProxy object and the second time the real target appears. There must be some kind of intransparent chaining but I've not found the source of that. The business object itself is injected into another service object. But beside that, the whole staff looks like the Spring.NET 1.2.0 sample.

  3. #3
    Join Date
    Jul 2006
    Location
    Vienna
    Posts
    8

    Default Transaction attribute and automatic proxy

    Maybe the first appearing target (the proxy) is based on the following line in the config:

    Code:
    <tx:attribute-driven transaction-manager="transactionManager" />
    But i still need the possibility of Spring transactions as well. Is there a solution to the problem, when one proxy is based on another proxy?

  4. #4
    Join Date
    Jan 2006
    Location
    Cambridge, UK
    Posts
    1,340

    Default

    Hi,

    I am currently looking into this. Actually the same advice instance shouldn't be called multiple - but one part of the issue is, that <tx:attribute-driven /> already registers a DefaultAutoProxyCreator instance internally. Registering a second instance manually is at least not necessary. Also the DefaultAutoProxyCreator automatically scans the context for IAdvisor and IAdvisors instances and applies them (according to their associated pointcut only of course). An alternative to using <tx:attribute-driven /> is to use e.g. an ObjectNameAutoProxyCreator:
    Code:
    <object id="txAutoProxyCreator" 
            type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
      <property name="ObjectNames">
        <list>
          <idref local="...."/>
        </list>
      </property>
      <property name="InterceptorNames">
        <list>
          <idref local="txInterceptor"/>
        </list>
      </property>
    </object>
    
    <object id="txInterceptor" 
            type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data">
      <property name="TransactionManager" ref="txManager"/>
      <property name="TransactionAttributeSource" ref="txAttributeSource"/>
    </object>
    
    <object id="txAttributeSource" type="Spring.Transaction.Interceptor.AttributeTransactionAttributeSource, Spring.Data" />
    
    <object id="txManager" type="..."/>
    I will ping back here as soon as I investigated the multiple advice execution a bit more.

    hth,
    Erich

  5. #5
    Join Date
    Jan 2006
    Location
    Cambridge, UK
    Posts
    1,340

    Default

    Quote Originally Posted by graphicsxp View Post
    I'm trying to use Attribute pointcut in order to apply my aroundAdvice to only the functions in my service which are decorated with a [SessionScope] attribute.

    Since I've done that, the code goes in the aroundAdvice 3 times before it goes into the invoked method ! If I don't use the pointcut, the aroundAdvice is only hit once before the invoked method executes and returns fine.
    plz post more of your config. Do you use <tx:attribute-driven> somewhere? Any other IAdvisor instances in your config?

    -Erich

  6. #6
    Join Date
    Jul 2006
    Location
    Vienna
    Posts
    8

    Default problem solved!

    thanks Erich! That was nearly the same what I thought without having a deep look into the spring sources

    I have changed my configuration of the transaction stuff and now all works pretty fine. I wonder, that nobody else has ever encountered that problem. It would be nice, if the "DefaultAdvisorAutoProxyCreator" verifies that it is not called twice.

  7. #7
    Join Date
    Jan 2006
    Location
    Cambridge, UK
    Posts
    1,340

    Default

    I wonder, that nobody else has ever encountered that problem.
    same here ;-). I am about to commit the code to avoid advice duplication when "double-proxying". So you still may end up with a proxy being proxied (which is perfectly legal) but duplicate advices will be removed from the "outer" proxy.

    I recorded this as SPRNET-1221. An implementation for a DAAPC that does not interfere with user configs is TBD though.

    -Erich

  8. #8
    Join Date
    Jun 2009
    Posts
    9

    Default Double triggering

    I'm getting the same results (advice triggering twice for methods decorated with Debug or Publish) with my IMethodInterceptor and my IAfterReturningAdvice advices:

    <!--AOP-->
    <object id="PublishAdvice" type="Spring.Aop.Support.AttributeMatchMethodPoint cutAdvisor, Spring.Aop">
    <property name="advice">
    <object type="Domain.Aop.PublishAdvice,Domain"/>
    </property>
    <property name="attribute" value="Domain.Aop.PublishAttribute"/>
    </object>

    <object id="DebugAdvice" type="Spring.Aop.Support.AttributeMatchMethodPoint cutAdvisor, Spring.Aop">
    <property name="advice">
    <object type="Domain.Aop.DebugAdvice,Domain"/>
    </property>
    <property name="attribute" value="Domain.Aop.DebugAttribute"/>
    </object>

    <!--TRANSACTIONS-->
    <object id="transactionManager"
    type="Spring.Data.Core.TxScopeTransactionManager,S pring.Data">
    </object>

    <object id="autoProxyCreator"
    type="Spring.Aop.Framework.AutoProxy.DefaultAdviso rAutoProxyCreator, Spring.Aop">
    </object>

    <object id="transactionAdvisor"
    type="Spring.Transaction.Interceptor.TransactionAt tributeSourceAdvisor, Spring.Data">
    <property name="TransactionInterceptor" ref="transactionInterceptor"/>
    </object>


    <!-- Transaction Interceptor -->
    <object id="transactionInterceptor"
    type="Spring.Transaction.Interceptor.TransactionIn terceptor, Spring.Data">
    <property name="TransactionManager" ref="transactionManager"/>
    <property name="TransactionAttributeSource" ref="attributeTransactionAttributeSource"/>
    </object>

    <object id="attributeTransactionAttributeSource"
    type="Spring.Transaction.Interceptor.AttributesTra nsactionAttributeSource, Spring.Data">
    </object>

    I don't get what I'm doing wrong??

    thanks,
    nisbus

  9. #9
    Join Date
    Jun 2009
    Posts
    9

    Default

    Sorry, my bad, I was actually raising the method twice (through context events) so there is no double triggering (except in my code)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •