title: Using AspectJ annotations without Spring
body: <p>I am fairly new to AOP. I am trying to create annotations in a maven project without Spring using AspectJ. However my the method I am trying to call using the @Aspect is not being called.</p>
  
  <p>This is what my pom looks like :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;test&lt;/groupId&gt;
  &lt;artifactId&gt;tanvi&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
  &lt;dependencies&gt;
      &lt;!-- https://mvnrepository.com/artifact/aspectj/aspectjrt --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;aspectj&lt;/groupId&gt;
          &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
          &lt;version&gt;1.5.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/aspectj/aspectjweaver --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;aspectj&lt;/groupId&gt;
          &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
          &lt;version&gt;1.5.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;aspectj&lt;/groupId&gt;
          &lt;artifactId&gt;aspectjtools&lt;/artifactId&gt;
          &lt;version&gt;1.5.3&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;aspectj-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.8&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;complianceLevel&gt;1.8&lt;/complianceLevel&gt;
                  &lt;source&gt;1.8&lt;/source&gt;
                  &lt;target&gt;1.8&lt;/target&gt;
              &lt;/configuration&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;phase&gt;process-sources&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;compile&lt;/goal&gt;
                          &lt;goal&gt;test-compile&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.6.2&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.8&lt;/source&gt;
                  &lt;target&gt;1.8&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p>The annotation looks like this :</p>
  
  <pre><code>@Target({ElementType.METHOD})
  @Retention(RetentionPolicy.RUNTIME)
  public @interface HasAccess {
      Access[] accesses();
      String message() default "You are not allowed to perform this operation";
  }
  </code></pre>
  
  <p>I created an annotation processor for my annotation :</p>
  
  <pre><code>@Aspect
  public class HasAccessAdvice {
      //    @Before("execution(* *.*(..)) &amp;&amp; @annotation(testAnnotation) ")
      @Before("execution(* *.*(..)) &amp;&amp; @annotation(hasAccess)")
      public void myBeforeLogger(JoinPoint joinPoint, HasAccess hasAccess) {
  
      System.out.println("Okay - we're in the before handler...");
      System.out.println("The test annotation value is: " + hasAccess.accesses().toString());
  
      Signature signature = joinPoint.getSignature();
      String methodName = signature.getName();
      String stuff = signature.toString();
      String arguments = Arrays.toString(joinPoint.getArgs());
      System.out.println("Write something in the log... We are just about to call method: "
                         + methodName + " with arguments " + arguments + "\nand the full toString: "
                         + stuff);
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am calling it in this call :</p>
  
  <pre><code>public class TestMe {
  
      @HasAccess(accesses = {Access.CREATE_PURCHASE})
      public void createPurchase(BigDecimal bigDecimal) {
          System.out.println("create Purchase called");
      }
  }
  </code></pre>
  
  <p>I created an aop.xml file and placed it in the same folder as pom.xml.</p>
  
  <pre><code>&lt;aspectj&gt;
      &lt;aspects&gt;
          &lt;aspect name="HasAccessAdvice"/&gt;
      &lt;/aspects&gt;
  &lt;/aspectj&gt;
  </code></pre>
  
  <p>When I call the method createPurchase, it runs without the @Before method being called first. Please help me with what I am missing. Most of the documentation/answers I found were Spring aligned. Any pointers to any tutorial or even another way of creating simple annotations without Spring would be greatly appreciated.</p>