Announcement Announcement Module
No announcement yet.
Advice called twice (once for the implementation and once for the proxy) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    The transaction documentation has been extensively reworked in light of numerous improvements in Spring 2.0. The updated documentation ha no more [TODO] placeholders, and will be included in the next release.

    In the interim, here is an example of how one specifies the transaction manager that is to be used...

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""
      <!-- this is the service object that we want to make transactional -->
      <bean id="fooService" class="x.y.service.DefaultFooService"/>
      <!-- the transactional advice (i.e. what 'happens'; see the <aop:advisor/> bean below) -->
      <tx:advice id="txAdvice" transaction-manager="txManager">
        <!-- the transactional semantics... -->
          <!-- all methods starting with 'get' are read-only -->
          <tx:method name="get*" read-only="true"/>
          <!-- other methods use the default transaction settings (see below) -->
          <tx:method name="*"/>
      <!-- this applies the above transactional advice to any FooService implementation bean -->
        <aop:advisor pointcut="execution(* *..FooService+.*(..))" 
      <!-- don't forget the DataSource -->
      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@rj-t42:1521:elvis"/>
        <property name="username" value="scott"/>
        <property name="password" value="tiger"/>
      <!-- similarly, don't forget the (correct) PlatformTransactionManager -->
      <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
      <!-- other <bean/> definitions here -->


    • #17
      Advice called twice (once for the implementation and once for the proxy)

      Hi Weslen,

      Define the pointcut on implemented class. Otherwise advisor gets called twice if point cut is defined on interface.


      • #18
        Got the same issue, even if I hardcoded the name of my implementation in the pointcut expression (the interface is IContractService).

        Here is my configuration :
        <tx:advice id="txAdvice" transaction-manager="txManager">
                <tx:method name="*" read-only="false" />
        <bean id="exceptionLoggerAdvice" class="fr.socle.log.ExceptionLoggerService">
             <property name="loggerName" value="" />
           <aop:pointcut id="servicePointcut"expression="execution(**(..))" />
            <aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut" />
            <aop:aspect id="afterService" ref="exceptionLoggerAdvice">
                <aop:after-throwing throwing="exception" method="afterThrowing" pointcut-ref="servicePointcut" />
        Both of my aspects are executed twice : no matter with the tx one which create 2 nested transactions with the same behavior (commit 2x or rollback 2x) but it's really bothering me with my loggerAdvice which logs every exception twice.

        Any advice ? ( )


        • #19
          Do not know if this thread is still alive but I came accross the same symptom : MethodInterceptor advice and around advice being called twice.

          I searched thru all my spring context config files and find out that I had the following declarations :

          <aop:config proxy-target-class="true" />

          <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy .DefaultAdvisorAutoProxyCreator">
          <property name="proxyTargetClass"><value>true</value></property>

          By removing the second declaration this solved my problem.

          Actually this is well documented in chapter 6.3 (Spring 2.0.x) :

          "The <aop:config> style of configuration makes heavy use of Spring's auto-proxying mechanism. This can cause issues (such as advice not being woven) if you are already using explicit auto-proxying via the use of BeanNameAutoProxyCreator or suchlike. The recommended usage pattern is to use either just the <aop:config> style, or just the AutoProxyCreator style."

          Maybe you have similar redundant declarations.


          • #20
            Declare Ponicut at class level