Announcement Announcement Module
Collapse
No announcement yet.
Issue with Multiple Beans of the same class and AOP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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):

    Code:
    <bean id="beanA" class="com.sample.impl.ClassA">
    </bean>
    
    <bean id="beanB" class="com.sample.impl.ClassA">
    </bean>
    I have defined the AOP configuration to wrap the processMessage call with transaction advice as follows:
    Code:
    <aop:config>
    	<aop:advisor
    	pointcut="execution(* com.sample.InterfaceA.processMessage(..))"
    			advice-ref="txAdvice" />
    </aop:config>
    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...

    Comment


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

      Comment

      Working...
      X