Results 1 to 3 of 3

Thread: Intercept only one implementation of an interface method?

  1. #1
    Join Date
    Jan 2005
    Location
    Sydney, Australia
    Posts
    32

    Default Intercept only one implementation of an interface method?

    Hi All,

    I have an interface with two different implementations. I want to apply some advice to only one of those implementations. I'm using the RegexpMethodPointcutAdvisor. However if I set up the regexp so that it matches the implementation method's signature, the advice never gets called. And obviously setting up the regexp to match the interface method's signature is not the behaviour I want, as it will match the other implementation as well.

    Is there any way I can make spring AOP match only a particular implementation of an interface method? I'm using spring 1.2RC1. Here's an excerpt of my config:

    Code:
        <bean id="connectionAdvice" class="connection.ConnectionInterceptor">
            ...
        </bean>
    
        <bean id="connectionAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
            <property name="advice">
                <ref bean="connectionAdvice"/>
            </property>
            <property name="patterns">
                <list>
                    <!-- Regexp to match the interface method sig - works, but also matches unwanted implementations -->
                    <value>service\.ConnectionMessageService\..*</value>
    
                    <!-- Regexp to match the implementation method sig - doesn't work -->
                    <value>service\.AxsResConnectionMessageService\..*</value>
                </list>
            </property>
        </bean>
    Cheers,
    Charles

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Your best option is probably to implement a custom pointcut with a MethodMatch.matches(Method m, Class targetClass) that checks for the target class you want.

    Rgds
    Rod
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Jan 2005
    Location
    Sydney, Australia
    Posts
    32

    Default

    Thanks Rob,

    I'll give it a go. I guess another option is to have the implementation that I want to advise simply delegate to another bean and apply the advice to this other bean instead. Not really very clean though.

    Is there any particular reason why you can't match on the actual implementation method signature as well as the interface method signature? It makes sense to me, but maybe I'm missing something.

    I must admit I'm a bit unclear on how I should be defining my pointcuts when it comes to interface vs implementation. What is the general rule? Should I specify the implementation method signature, or the interface method signature? Or both? What exactly will Spring try to match on? What about when using JDK 1.5 annotations (eg: @Transactional)? Should I annotate the interface method, or the implementation of that method?

    Thanks,
    Charles

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. PerformanceMonitorInterceptor
    By tnist in forum AOP
    Replies: 3
    Last Post: Aug 24th, 2005, 01:39 PM
  5. Other Hibernate DAO LazyInitializationExceptions
    By bernardsirius in forum Data
    Replies: 5
    Last Post: Feb 18th, 2005, 04:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •