![]() |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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" />
|
|
#3
|
|||
|
|||
|
Maybe the first appearing target (the proxy) is based on the following line in the config:
Code:
<tx:attribute-driven transaction-manager="transactionManager" /> |
|
#4
|
|||
|
|||
|
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="..."/>
hth, Erich |
|
#5
|
|||
|
|||
|
Quote:
-Erich |
|
#6
|
|||
|
|||
|
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
|
|||
|
|||
|
Quote:
I recorded this as SPRNET-1221. An implementation for a DAAPC that does not interfere with user configs is TBD though. -Erich |
|
#8
|
|||
|
|||
|
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
|
|||
|
|||
|
Sorry, my bad, I was actually raising the method twice (through context events) so there is no double triggering (except in my code)
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|