• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Spring AspectJ within expression

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please explain me how Spring AspectJ ‘within’ expression works? I have an advice which needs to be invoked when Target.save() is called but not when when Target is called from RelationshipBean class. For this I have below expression.
Please let me know where I am doing wrong.

@Pointcut("execution(* com.*RelationshipService.*save*(..))")
private void anyPublicOperation() {
}

@Pointcut("!within(com. staticData.*RelationShipBean))")
private void excludeRelationship() {
}

@Around("inTrading() && excludeRelationship()")
public Object cacheCalls(ProceedingJoinPoint pjp) throws Throwable {
}

It seems Spring completely ignores within expression and invoke cacheCalls even if I call from RelationshipBean. Please let me know where I am doing wrong.
 
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The within pointcut refers to any join point in the specified class, so when you add !within to a pointcut you are basically saying that you don't want the advice to apply within the class.
You may want to double check the syntax of your !within pointcut, especially the use of wild cards. For example, if I have class MyService within package test.web.services, and I have aspect Logger in package test.web.aspects and I do not want the aspect to apply the advice to MyService, the pointcut will look like

using

all result without a match at !within and therefore the advice will be applied.
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic