Results 1 to 3 of 3

Thread: Accessing target in advice

  1. #1
    Join Date
    Dec 2005
    Posts
    8

    Default Accessing target in advice

    Hello all. I'm having problems defining a pointcut so I can access the target object:

    Application Context
    Code:
    <aop:aspectj-autoproxy/>
    <bean id="logging" class="blah.Logging" />
    Pointcut
    Code:
    @Pointcut( "execution( * blah.AddressService.getAddress(..) )" )
    public void getAddress() {}
    Advice
    Code:
    @Before(    "blah.SystemArchitecture.getAddress() && args( id ) && target( addressService )" )
    public void logGetAddress( Long id, AddressService addressService ) {
    ...
    }
    When I try and deploy it I get:
    Code:
    org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer$AmbiguousBindingException: Still 2 unbound args at this(),target(),args() binding stage,
     with no way to determine between them
    I'm probably doing something stupid so if anyone can point me in the right direction I'd be very greatful!

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

    Default

    If you want to access the target object you will have to do this programmatically.

    Code:
    @Before("blah.SystemArchitecture.getAddress() && args( id )" )
    public void logGetAddress( JoinPoint jp, Long id) {
      AddressService target = (AddressService) jp.getTarget();
      ...
    }
    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
    Dec 2005
    Posts
    8

    Default

    Ah ok, that would explain why I'm having problems. Thankyou

Posting Permissions

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