Results 1 to 3 of 3

Thread: Different advice for different interfaces

  1. #1
    Join Date
    Aug 2005
    Posts
    39

    Default Different advice for different interfaces

    Folks,

    I have a proxy target object which implements several different interfaces. I'd like the proxy to have different Advice for each of these interfaces.

    However, I can't find an appropriate Advisor in the API. This doesn't seem like a particularly exotic thing to want to do, which suggests I'm looking for the wrong thing, but a subtype of PointcutAdvisor would seem like the right place to look.

    Can anyone advise (bdump-tish!) me on this?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Assuming you have Spring 2.0 with the aop style config that is a breeze.

    Code:
    <aop:config>
      <aop:pointcut id="interface1" expression="exectution (* YourInterface1.*(..))" />
      <aop:pointcut id="interface2" expression="exectution (* YourInterface2.*(..))" />
      <aop:advisor pointcut-ref="interface1" advice-ref="interface1-advice"/>
      <aop:advisor pointcut-ref="interface2" advice-ref="interface2-advice"/>
    </aop:config>
    Classes implementing 1 of the 2 interfaces will have 1 advice added, classes implementing both interfaces will have both advices added. The same should be possible with old-style configuration but probably more verbose...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2005
    Posts
    39

    Default

    Thanks Marten. I shouldn't mentioned that I needed to this programmatically rather than with XML config, but I think I can cobble something together now.

Posting Permissions

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