-
Jun 28th, 2010, 06:20 AM
#1
Simple 2 class example
Hi there,
sorry if there's already an answer for this request somewhere, I searched the forum on keyword "example" and got the message that the search word is either too short or too long and that therefor it was left out of the search -> resulting in an empty list...
Also I saw there's a request for a big example which got directed to a Roo(?)-something. I visited that roo page and got another bunch of extra stuff obfuscating any simple
"download-and-mess/play-with-till-i-get-the-clear-picture" example... (this is still so typical in IT world -_-" )
Yes, I do understand the concept of AOP. One has his common OOP app and performs actions triggered when certain methods are called, without touching the original app.
No, I do not understand how to get the advice executed. I kind of followed the example at http://www.infoq.com/articles/Simpli...nterprise-Apps (using @Aspect, @Pointcut and @AfterReturning) -> I created an aspect class in my code, defining a pointcut and an afterreturning advice, I compiled and nothing extra happens when I call the method specified in the pointcut...
Hence, my request.
What I need is a simple 2 class example (1 object to advise on + 1 advising object), that I can compile (with or without Spring) and that w.o.r.k.s.
Thanks in advance for any help 
Cheers,
Klaas
-
Jun 28th, 2010, 07:13 AM
#2
attempts
I tried the following, starting with the commented lines not to be commented
nothing works however - even if I put everything in 1 class,
it still doesnt print "HelloAspect".
the only way I know to get it printed is the OOP way, calling the method 'olleh' explicitly. But thats exactly what I do not want to do.
I want to understand how to set the AOP way correctly. 
//----------------------------------------------------
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class SpringAOPExample {
public static void main(String[] s) {
System.out.println("HelloMain");
//new SpringAOPExample().new MyClass().hello();
System.out.println("GoodbyeMain");
}
// public class MyClass/*SpringAOPExample*/ {
// public void hello() {
// System.out.println("HelloWorld");
// }
// }
// @Aspect
// public class MyAspect/*SpringAOPExample*/ {
@Pointcut("execution(* main(..))")
public void pointMethod() {
// System.out.println("HelloPoint");
}
@AfterReturning("pointMethod()")
public void olleh() {
System.out.println("HelloAspect");
}
// }
}
Klaas
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules