Bindings, Platforms, and Innovation
This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.
Tracking change and innovation in the enterprise software development community
Posted by Floyd Marinescu on Aug 09, 2006 10:01 PM
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
Download the Free Adobe® Flex® Builder 3 Trial
Adobe® Rich Internet Application Project Portal
How Java Developers Can Write Great SQL
I enjoyed reading it. Thanks Adrian.
What's "infoq.com/spring"? A topic? Why isn't it listed in the topics above?
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.
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!
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!
Hi Peter, what page/paragraph do you notice the problem? I have the same version and it seems to print fine.
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.
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
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.
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
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
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
(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
This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.
This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.
This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.
This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.
This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.
After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.
IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.
Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.
13 comments
Watch Thread Reply