Spring has a very good support for AOP, but the main problem is, all the beans need to be managed by Spring's container, otherwise, AOP won't work. This is ideal if you have a completely Spring-powered project. But it won't do you any good if you are not.
[Not exactly: Spring could inject values into non-Spring bean]
1. define bean in config as abstract plus the configurations, the id, let's see, is "testBean1"
2. add @configurable("testBean1") before the class in .java file.
3. add
It seems behind the scene, it's still AspectJ is doing all the work.
Guice has the same problem, the Java classes have to be binded by Guice's injector to have AOP work.
That leaves only one choice, AspectJ.
With AspectJ, we could have a very powerful tool to work on big project.
Imagine your boss gives you this task: log the result whenever a method named getMyMoneyBack() gets called. Sound easy? Not so fast, the problem is getMyMoneyBack() exists in thousands of classes, and they are called by millions of times. You really don't want to go to millions of places to put your log code there, do you?
With AspectJ, life is much easier.
You define a point cut like:
pointcut logGetMyMoneyBack() : call (* *.getMyMoneyBack(..))
String around() : logGetMyMoneyBack
{
String result = proceed();
System.out.println(result );
return result;
}
return proceed();