• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

want an advisor for many pointcut

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all:
In my new project, we need to program many existing projects to intercept some action method in order to add some extra work, mainly synchronize the modified data into another db. We just need an advice but tens of pointcut, maybe over 100, from different existing projects. I want to configure the action and method info in a xml file, and then apply them as pointcut through some way. The configuration info is like below, just temporary thought.

My question is that besides a customized advisor extending StaticMethodMatcherPointcutAdvisor and implementing the method match throung the way of , such as storing the action and method names in a List and determining by List.contains(), is there an other easy and efficient way ? Such as @aspectj and aspectj schema. At least I haven't found a good way, cause it's horrible to write a very long pointcut expression in the applicationContext.xml, there're too many methods and actions to write, and it's hard to read and maintain all these pointcut expression. It's better not to import other jar file beside spring library.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is your best solution.

1) Create your own Annotations and then annotate all the methods you want advised.
then write your pointcut expression to match the annotation.

for instance

"execution(@com.myapp.annotations.MyAnnotation * *(..))"

Now any method that is annotated with @MyAnnotation will match that pointcut expression. No more need of 100 pointcut expressions.

Here is my definition of that annotation




That's it.

Mark
 
Ranch Hand
Posts: 88
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also use <aop:pointcut/> tags in spring xml, but i'll advice to use them only if you can define some pattern over the join points.
say com.abc.*.Db*.u*(..) then it will work well.
 
Kurt Xu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:Here is your best solution.

1) Create your own Annotations and then annotate all the methods you want advised.
then write your pointcut expression to match the annotation.

for instance

"execution(@com.myapp.annotations.MyAnnotation * *(..))"

Now any method that is annotated with @MyAnnotation will match that pointcut expression. No more need of 100 pointcut expressions.

Here is my definition of that annotation




That's it.

Mark


It works. If it doesn't need cglib and asm jar file it would be perfect. Our company' system is a little rigid, which means we can't easily add jar file to the existing web project. I'm very curious with that how webwork implements interceptor without cglib and asm. After all interceptor is same of aop.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your classes have interfaces and implement them. Them Spring will create DynamicProxies. No need for cglib in that scenario.

Mark
 
Kurt Xu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:If your classes have interfaces and implement them. Them Spring will create DynamicProxies. No need for cglib in that scenario.

Mark



Yes, I know that , unfortunately, some BO classes have interface, some don't. Looks like all I can do is to persuade my boss to add jar file.
 
reply
    Bookmark Topic Watch Topic
  • New Topic