Announcement Announcement Module
No announcement yet.
Issue with Multiple Beans of the same class and AOP Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with Multiple Beans of the same class and AOP

    I have a situation where I have two beans defined which are of the same implementation class (ClassA) and implement the same interface (in this case InterfaceA):

    <bean id="beanA" class="com.sample.impl.ClassA">
    <bean id="beanB" class="com.sample.impl.ClassA">
    I have defined the AOP configuration to wrap the processMessage call with transaction advice as follows:
    	pointcut="execution(* com.sample.InterfaceA.processMessage(..))"
    			advice-ref="txAdvice" />
    The problem I have found is that the txAdvice only gets applied to the first bean (in this case beanA) and does not get applied to beanB. If I remove beanA from the application context, then beanB gets the transaction advice. This does not seem correct. I am using Spring 2.5.3. Any ideas on how to make the pointcut intercept calls to both beans processMessage method.

  • #2
    It works like a charm here so it must be something in your local environment...


    • #3
      Thanks - Found the issue.

      The issue was that a method on ClassA was invoking the processMessage method directly on itself. When I invoked the method from another class that was using the interface it worked correctly.