Announcement Announcement Module
Collapse
No announcement yet.
Accessing target in advice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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();
      ...
    }

    Comment


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

      Comment

      Working...
      X