• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is Spring AOP really an effective strategy?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm very new to Spring AOP so this might just be something I've over looked. The situation is our application wants a sound Logging strategy that eliminates the complexity from the responsibility of the Developer. Spring AOP seems to do that except for one issue. We have a multi tier application with what could be 100's of apps wired into the execution of our program. If any of those apps would all of a sudden want to write a specific message, does the Developer now have to change the aspect and then re-wire the xml? Also, I'm assuming every single APP would have to be wired through the xml in the form of proxies right?

If an APP needs to write a specific message anyway, wouldn't it make more since to just take care of it within the app? By doing this through AOP, this would seem to make our "base" wiring xml to be just enormous with every single app registered?

Is there a simple way around this? I know I wouldn't have to register each method, but the apps still would need proxies set up right?

AOP makes since for a trace type log strategy but I can't quite seem to see the benefit for a complete logging strategy.
 
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
OK, I got confused in reading what exactly you are looking for or what would cause you issues.

But, I think I still might have an elegant solution for you.

AOP is a perfect strategy for all Logging.

You could create your own Annotation that you has an attribute for the message you want printed. Then create your Pointcut to match methods with that annotation, and you can pass that annotation on that method into your aop advice method, and your aop advice method would be generic enough to handle new messages, new applications, or anything.

Hope that is what you meant and that I helped.

Mark
 
Raistlen Majere
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you may be right on target but I will have to do some more research.

If I have 100 apps, and everyone of their execute methods needs to log "I'm Executing!" (just an example), do all 100 apps need proxies set up in spring?

Thanks for your reply and I will look into annotations.
 
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

Raistlen Majere wrote:I think you may be right on target but I will have to do some more research.

If I have 100 apps, and everyone of their execute methods needs to log "I'm Executing!" (just an example), do all 100 apps need proxies set up in spring?

Thanks for your reply and I will look into annotations.



Still a bit confused 100 apps each of them Spring apps?

I don't understand "do all 100 apps need proxies set up in spring?"

Do you mean all different .war files each starts up their own Spring container, each with their own configuration

of

Do you mean one Spring application with over 100 beans in it.

In any case, if you want AOP there are three mechanisms to get that code to log. 1) Dynamic Proxies at runtime based on bean's interface. 2) CGLIB jar in your classpath, create proxies at runtime by extending your class. 3) AspectJ running ajc after compiling will add the code through byte code instrumentation, meaning the code is injected into you .class as if you had coded it there.

Now about proxies, I am sensing you think that proxies are a bad thing. Maybe that you think it slows things down. I can guarantee you, by experience and by actually timing things, proxies will not make a difference to your application, especially one that just logs a message. And that many servers out there use these Dynamic Proxy pattern themselves, like all the app servers. If it was a bad idea, all of them wouldn't be using it.

Hope that helps.

Mark
 
Raistlen Majere
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I apologize for confusion. It would be more like a hundred beans injected to create a spring app. Within those beans I would need to monitor anytime lets say a writeMessage(String strInput) was called.

I was hoping there was a way to just monitor the method itself without setting up a proxy for all 100 beans. In other words, make the Spring xml file easier to manage.

I don't think proxies are a bad thing, I just think having to create 100 of them to monitor the same method is.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raistlen Majere wrote:
I was hoping there was a way to just monitor the method itself without setting up a proxy for all 100 beans. In other words, make the Spring xml file easier to manage.



You don't have to setup proxies for 100 of beans - you just need to configure your logging aspect in Spring XML and spring will create the proxies behind the scene (and any solution which has the two words Spring and AOP will have Proxies involved!!)

To be frank - I think you need to understand AOP before you try coding with it.

Spring provides a free online AOP training that I think is really good - give it a try
 
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
To add to Sam's stuff. Based on our pointcut expression, Spring will only proxy those beans that have methods that match the expression. If a bean doesn't have that method, then no proxy. For the methods that don't match that are also in the bean that has one method that matches, the proxy does nothing when calling those methods, it just goes directly to the bean and calls that method.

But to re-iterate what Sam said, you as a developer never creates a Proxy, Spring does that for you.

Mark
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic