Women in Technology

Hear us Roar



Article:
  An Introduction to Aspect-Oriented Programming with the Spring Framework, Part 1
Subject:   The diagrams are wrong?
Date:   2004-08-19 04:44:10
From:   patrickchaumette
Hello Russ,


I was just reading your article and stuck on the diagrams.


On the left it shows an instance of MyClass which calls the application context to get a handle on a certain bean.
Then it is shown that before() is called from the instance of MyClass, and then foo()!


Now did I misunderstand something here? Somehow I miss the proxy object which is returned from the application context, which has a foo() method.
In my understanding, the instance of MyClass calls only this foo() method on that proxy object, which then, in the implementation of the proxy causes the before() getting called on the before advice instance, the foo() getting called on the business logic and then the after() getting called on the after advice instance.


Can you tell me if I am completely wrong here? Doesn't Spring do runtime AOP with Proxies?


Thank you for your time,


greetings,


Patrick

Full Threads Oldest First

Showing messages 1 through 6 of 6.

  • Russell Miles photo The diagrams are wrong?
    2004-08-19 21:24:37  Russell Miles | O'Reilly AuthorO'Reilly Blogger [View]

    Hi Patrick,

    hmmm, don't think you're necessarily wrong but I believe that conceptually (from an AOP view but not exactly how Spring implements things) the before() advice is executed before the call to the foo() method (this may and is indeed achieved using proxies in Spring, so you're spot on) but I was really aiming at getting the AOP principles across without getting too detailed on how Spring achieves this.

    This is a practice that is getting to be more and more common in the AOP field, focussing on what the AOP directives are specifying and losing some of the focus on the particulars of how a specific implementation would achieve those directives. So I think you're right but I think the concepts the diagrams are putting across are still valid.

    Hope that clears things up a bit and thanks for the comment :)

    Cheers
    • Injecting both Transactions & MethodAdvices
      2005-08-08 18:11:37  EtiKatta [View]

      Hi,
      Great work by you people. I have a simple question.

      We have given instructions on how to configure for Transactionality by using TransactionProxyFactoryBean and also we have given instructions on how to configure ProxyFactoryBean for Advices.

      My requirement is to apply both of these to the same UserManagerDelegate class and if I do them separate (as separate beans in .xml file), then I am only looking up for one bean ctx.getBean("UserManager"); and this only applies one of the above 2 configurations. If I use it for Transactions, it doesn't work for other 'before' and 'after' method advices. If I use this for 'before'&'after' method advices, then it doesn't work for Transactions.

      How can I configure my UserManager (interface) and UserManagerImpl (implementation) to take care of both (a) Transactionality and (b) before&after method advices.

      Please help.

      Thank you very much.
      • Injecting both Transactions & MethodAdvices
        2007-01-04 14:46:19  kcav8or [View]

        Did you ever find a solution to this? I have the same requirement.
        • Injecting both Transactions & MethodAdvices
          2007-01-04 15:19:46  kcav8or [View]

          I answered my own question after a search of the Spring Support Forums. I added the LoggingThrowsAdvice as a preInterceptor on the TransactionProxyFactoryBean as follows:


          <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
          <property name="sessionFactory"> <ref local="sessionFactory" /> </property>
          </bean>

          <bean id="loggingThrowsAdvice" class="com.myapp.aop.LoggingThrowsAdvice">
          </bean>

          <bean id="txProxyTemplate" abstract="true"
          class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
          <property name="transactionManager" ref="transactionManager"/>
          <property name="transactionAttributes">
          <props>
          <prop key="*">PROPAGATION_REQUIRED</prop>
          </props>
          </property>
          <property name="preInterceptors">
          <list>
          <ref local="loggingThrowsAdvice" />
          </list>
          </property>
          </bean>
        • Injecting both Transactions & MethodAdvices
          2007-01-04 15:12:52  kcav8or [View]

          I answered my own question after a search of the Spring Support Forums. I added the LoggingThrowsAdvice as a preInterceptor on the TransactionProxyFactoryBean as follows:


          <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
          <property name="sessionFactory"> <ref local="sessionFactory" /> </property>
          </bean>

          <bean id="loggingThrowsAdvice" class="com.myapp.aop.LoggingThrowsAdvice">
          </bean>

          <bean id="txProxyTemplate" abstract="true"
          class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
          <property name="transactionManager" ref="transactionManager"/>
          <property name="transactionAttributes">
          <props>
          <prop key="*">PROPAGATION_REQUIRED</prop>
          </props>
          </property>
          <property name="preInterceptors">
          <list>
          <ref local="loggingThrowsAdvice" />
          </list>
          </property>
          </bean>
    • The diagrams are wrong?
      2004-08-20 08:48:13  patrickchaumette [View]

      Hello Russ,

      thank you for your fast answer!
      Pfeww... You got me really confused :-)

      Still...

      I have no problems with the concepts, maybe a precision on that point(..I was really aiming at getting the AOP principles across without getting too detailed on how Spring achieves this..) would have helped to clarify the diagrams, because the article states in another direction ..., we focus on just the AO facilities provided by Spring. and ...This article will show you how to use the following AOP concepts as they are implemented in the Spring framework....

      Sure conceptually before() is executed before foo() is called, but in order to understand it one has to say on which objects.

      I can't get warm with those UML sequence diagrams (or aren't they meant to be?), either they should really show only the concept of AOP unrelated to a specific technology (e.g. it shows AppContext.getBean(), this is specific here in Spring and doesn't directly relate to AOP) or they should show what really happens when you use AOP and Spring (e.g. adding the missing Proxy and all would be clear
      MainApp->getBean("bl")->IBusinessLogic.foo()->Proxy.foo()->before()->BusinessLogic.foo()->afterReturning()).

      Anyway, thanks again for the clarifications,
      I am curious about the Part 2 of your series.

      Greetings,

      Patrick