Announcement Announcement Module
No announcement yet.
Can't get AOP to call advice methods Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't get AOP to call advice methods


    I have created a very simple AOP example, based on an example I found in Spring in Action but I can't get the example to work.

    I have 3 beans: HelloApp, GreetingServiceImpl and ALogger. I want to execute the methods ALogger.enter and ALogger.exit when every method is executed, but this is not happening and I don't understand why not. I am new to AOP so no doubt this is a simple configuration problem or similar

    HTML Code:
    <bean id="greetingService" class="">
        <property name="greeting" value="Hello, world!"/>
    <bean id="logger" class=""/>
       <aop:aspect id="loggerAspect" ref="logger">
          <aop:pointcut id="loggerPointCut" expression="execution(* *(..))"/>
          <aop:before pointcut-ref="loggerPointCut" method="enter" />
          <aop:after pointcut-ref="loggerPointCut" method="exit" />

  • #2
    How are you calling the methods on the greetingService? Do you use the one created in the spring context or a new one? What would you expect to happen/see?


    • #3

      Thanks for your reply. I have fixed the problem. I was using an instance of BeanFactory when I should have been using an instance of ApplicationContext.