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

  • Can't get AOP to call advice methods

    Hello,

    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="com.fujitsu.spring.examples.GreetingServiceImpl">
        <property name="greeting" value="Hello, world!"/>
    </bean>
    
    <bean id="logger" class="com.fujitsu.spring.examples.ALogger"/>
    	
    <aop:config>
       <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" />
       </aop:aspect>
    </aop:config>

  • #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?

    Comment


    • #3
      Marten,

      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.

      Comment

      Working...
      X