Announcement Announcement Module
No announcement yet.
Simple 2 class example Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 (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


  • #2

    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;

    public class SpringAOPExample {
    public static void main(String[] s) {
    //new SpringAOPExample().new MyClass().hello();
    // 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");

    public void olleh() {
    // }