Creating an aspect

In this section you will create a new aspect and add a pointcut and some advice.

  1. In the Package Explorer view, select the helloworld package. From the package's context menu, select New > Aspect.
  2. Make sure that Hello World appears in the Source Folder field and that helloworld appears in the Package field. In the Name field, type World.

    New aspect wizard

  3. Click Finish to create the new aspect.
  4. The new file is opened in the editor. It contains the new aspect, the constructor and comments.
  5. Change the body of the aspect to the following:


    public aspect World {

         pointcut greeting() : execution(* Hello.sayHello(..));

         after() returning() : greeting() {
             System.out.println(" World!");
         }

    }

  6. Save the file.

Related concepts

AspectJ editor

Related tasks

Creating AspectJ elements