InfoQ

News

InfoQ Article: Simplifying Enterprise Apps with Spring 2 and AspectJ

Posted by Floyd Marinescu on Aug 09, 2006 10:01 PM

Community
Java
Topics
AOP,
Change
Tags
No Fluff Just Stuff Symposiums,
AspectJ,
Spring
Spring has long provided a proxy-based service to apply Aspects to Spring-managed beans. However, when it comes to requirements that impact multiple points in your domain model, Spring AOP is of much less assistance, but AspectJ is a natural fit.  AspectJ aspects don't need any special proxy creation, and can happily advise objects created at runtime either in your application code or by frameworks you may be using. AspectJ is also a very good solution when you want to modularise behaviour that cuts across all the different layers of your application, or that is in any way performance sensitive.

Adrian Colyer, AspectJ lead and Chief Scientist at Interface21 has contributed an excellent article which shows how to use Spring 2's new AspectJ integration features followed by a roadmap for the adoption of Aspect Oriented Programming on an enterprise project, with lots of specific examples of how and where to apply Aspects.

Adoption of AOP can proceed in a number of phases: start out by taking advantage of aspects that Spring supplies out-of-the-box, and then you can add your own @AspectJ aspects using Spring AOP in the web, service, and data-access layers. AspectJ itself can be used to improve development productivity without introducing any runtime dependency on AspectJ. Going further, infrastructural requirements that cut across multiple layers of your application can be simply implemented using AspectJ aspects. Finally, you can use aspects to simplify the implementation of your domain model itself.
Read Simplifying Enterprise Apps with Spring 2 and AspectJ.  See also infoq.com/spring, infoq.com/aop

Adrian is also speaking at The Spring Experience, along with the rest of the spring experience.

13 comments

Reply

Excellent article by Jonas Bonér Posted Aug 9, 2006 11:05 AM
infoq.com/spring by Geoffrey Wiseman Posted Aug 9, 2006 4:06 PM
Re: infoq.com/spring by Floyd Marinescu Posted Aug 9, 2006 5:24 PM
Great article! by Michael Klishin Posted Aug 9, 2006 11:33 PM
Printing article on Firefox is not correct by Peter Bona Posted Aug 10, 2006 3:14 AM
Re: Printing article on Firefox is not correct by Floyd Marinescu Posted Aug 10, 2006 8:32 AM
Re: Printing article on Firefox is not correct by Peter Bona Posted Aug 10, 2006 9:18 AM
afterThrow() by Cedric Beust Posted Aug 10, 2006 2:33 PM
Re: afterThrow() by Adrian Colyer Posted Aug 11, 2006 2:42 AM
Sources by William Louth Posted Aug 15, 2006 12:41 AM
controller aspectj question by Weng Guerra Posted Sep 26, 2007 8:04 AM
Re: controller aspectj question by Sebastian Jancke Posted Jun 30, 2008 6:30 PM
Re: controller aspectj question by Sebastian Jancke Posted Jun 30, 2008 6:33 PM
  1. Back to top

    Excellent article

    Aug 9, 2006 11:05 AM by Jonas Bonér

    I enjoyed reading it. Thanks Adrian.

  2. Back to top

    infoq.com/spring

    Aug 9, 2006 4:06 PM by Geoffrey Wiseman

    What's "infoq.com/spring"? A topic? Why isn't it listed in the topics above?

  3. Back to top

    Re: infoq.com/spring

    Aug 9, 2006 5:24 PM by Floyd Marinescu

    What's "infoq.com/spring"? A topic? Why isn't it listed in the topics above?
    If you look beneath the body of the article, you'll see "Tags Spring, AspectJ". You can click on those to see any all content on InfoQ about Spring or AspectJ. If you look at the top of the article you can see "topic - AOP", which functions the same. I added a link manually to the news item linking to this article so that people would notice the functionality.

  4. Back to top

    Great article!

    Aug 9, 2006 11:33 PM by Michael Klishin

    Very nice article on AOP. Probably the most clean explanation of AOP terminology and principles that I've ever read. Keep on a great job, i21 & InfoQ!

  5. Back to top

    Printing article on Firefox is not correct

    Aug 10, 2006 3:14 AM by Peter Bona

    When clicking on the print image right above, Firefox (1.5.0.6) is leaving some text out on the right, you cannot see the whole text. IE works fine. Could you pls check if there is something you could do about it? Thanks! Thanks for the article, it is really nice!

  6. Back to top

    Re: Printing article on Firefox is not correct

    Aug 10, 2006 8:32 AM by Floyd Marinescu

    Hi Peter, what page/paragraph do you notice the problem? I have the same version and it seems to print fine.

  7. Back to top

    Re: Printing article on Firefox is not correct

    Aug 10, 2006 9:18 AM by Peter Bona

    Like this page. I mean http://www.infoq.com/articles/Simplifying-Enterprise-Apps. I was playing with the screen resolution and settings in Print Preview, but none of the attempts worked. Anyway, I managed to print it in IE and that is fine for now. Thanks.

  8. Back to top

    afterThrow()

    Aug 10, 2006 2:33 PM by Cedric Beust

    Hi Adrian, Quick question: in the section about throwing, it's not clear that your afterThrowing() pointcut *replaces* the initial exception. I'm assuming that's what it does, right? It wouldn't make much sense to throw the original exception and then a DAOException, but you might want to clarify how this replacement actually works. -- Cedric

  9. Back to top

    Re: afterThrow()

    Aug 11, 2006 2:42 AM by Adrian Colyer

    Hi Cedric, Your interpretion is correct. If after throwing advice itself throws an exception, then the exception thrown by the advice will be seen by the client. If the after throwing advice completes normally, then the original exception will propagate to the client. The consequence of this is that you can use after throwing for exception *translation*, or for logging or taking other additional actions, but you can't use it to *handle* an exception condition. For that you have to use around advice, with a pattern that looks like this:

    Object around() : some_pc() {
      try {
        return proceed();
      }
      catch(ExceptionToBeHandled ex) {
        // handle condition here
        return exceptionalConditionReturnValue;
      }
    }
    
    (or the equivalent in @Aspect or Spring XML styles). Regards, Adrian.

  10. Back to top

    Sources

    Aug 15, 2006 12:41 AM by William Louth

    Hi Adrian, Are you planning on releasing the sources. It would be great to show how one you easily implement the profiling strategy mapping to our Tracer API (http://www.jinspired.com/products/jxinsight/api/com/jinspired/jxinsight/trace/Tracer.html) and have it easily integrated within our management console while adding additional JMV resource metrics (cpu, thread waiting, thread blocking, gc, object allocs). We previously published a performance insight article based on our Spring 1.x trace extension. http://www.jinspired.com/products/jxinsight/springtracing.html Regards, William Louth JXInsight Product Architect JInspired "Java EE tuning, testing, tracing, and monitoring with JXInsight" http://www.jinspired.com

  11. Back to top

    controller aspectj question

    Sep 26, 2007 8:04 AM by Weng Guerra

    Hi, Thanks for the good article. Though I have a quick question. Just want to ask how would I be able to forward a user to an error page after using pointcut on that method. Say I have method in com.my.controllers.AnswerQuestion processQuestion(blah, blah){ //do something return “success”; } then I have this aop config The main question is how would you redirect the user not to “success” but to “errorpage”. Ofcourse I dont want to do big change on processQuestion() method, the aim is to let the AOP manage it. Thanks!

  12. Back to top

    Re: controller aspectj question

    Jun 30, 2008 6:30 PM by Sebastian Jancke

    Weng Guerra, Try something like: Thats my class: public class Bar { public String foo(int x) { return "success"; } } And with this Aspect, i replace the outcome of foo(x): public aspect ReplaceAspect { pointcut yourMethodPointcut(Bar bar, int x): target(bar) && args(x) && call(public String Bar.foo(int)); String around(Bar bar, int x) : yourMethodPointcut(bar, x) { proceed(bar, x); return "errorpage"; } } -Sebastian Jancke

  13. Back to top

    Re: controller aspectj question

    Jun 30, 2008 6:33 PM by Sebastian Jancke

    (Sorry, I forgot the html-pre...) Weng Guerra, Try something like:

    public class Bar { 
      public String foo(int x) { 
        return "success"; 
      } 
    } 
    
    And with this Aspect, i replace the outcome of foo(x):
    public aspect ReplaceAspect { 
      pointcut yourMethodPointcut(Bar bar, int x): 
        target(bar) && args(x) &&
        call(public String Bar.foo(int)); 
    
      String around(Bar bar, int x) : yourMethodPointcut(bar, x) { 
        proceed(bar, x); 
        return "errorpage"; 
      } 
    } 
    
    -Sebastian Jancke

Exclusive Content

Typemock: Past, Present and Future

Eli Lopian of Typemock answers a few questions on Typemock origins and where Typemock is headed.

Agile in Practice: What Is Actually Going On Out There?

Scott Ambler talks about actual data resulting from surveys made during 2006-2008, showing how Agile is perceived and implemented within organizations.

Building Smart Windows Applications

From QCon 2008, Daniel Moth presents on using Visual Studio 2008 and .NET 3.5 to create compelling rich Windows applications.

Joshua Kerievsky about Industrial XP

Joshua Kerievsky, founder of Industrial Logic, talks about Industrial Extreme Programming which extends XP by including practices dealing with management, customers and developers.

Jeff Barr Discusses Amazon Web Services

Amazon Web Services (AWS) Evangelist Jeff Barr discusses SimpleDB, S3, EC2, SQS, cloud computing, how different Amazon services interact, origins of AWS, AWS globalization and the March AWS outage.

More Than Just Spin (Up) : Virtualization for the Enterprise and SaaS

Cloud services have helped bring virtualization to the forefront. Its full power however, also includes other benefits such as high availability, disaster recovery, and rapid provisioning.

Ruby Beyond Rails

John Lam talks about his path to dynamic languages, some of the problems of making IronRuby run fast, and how the DLR helps with implementing languages.

VMware Infrastructure 3 Book Excerpt and Author Interview

VMware Infrastructure 3: Advanced Technical Design Guide and Advanced Operations Guide provides a wealth of practical insights into setting up virtualization in todays corporate environments.