title: Spring AOP + AspectJ maven plugin - Internal method call doesn't work
body: <p>Java + Spring + Maven application.<br>
  Unable to make Internal call from annotation based public method.</p>
  
  <p>Prerequisite</p>
  
  <ol>
  <li>Java-Version: 1.7.</li>
  <li>Project: <strong>AspectProject</strong> > Post build it will create jar file.</li>
  <li>Client:  <strong>AspectClient</strong> : which has dependency of "AspectProject".</li>
  </ol>
  
  <p><strong>AspectProject</strong></p>
  
  <ol>
  <li>pom.xml</li>
  </ol>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;properties&gt;
          &lt;java.version&gt;1.7&lt;/java.version&gt;    
          &lt;maven.compiler.source&gt;1.7&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;1.7&lt;/maven.compiler.target&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;  
          &lt;springframework.version&gt;4.1.2.RELEASE&lt;/springframework.version&gt;        
          &lt;org.aspectj-version&gt;1.7.0&lt;/org.aspectj-version&gt;
    &lt;/properties&gt;
  
    &lt;dependencies&gt;
  
      &lt;!-- Spring --&gt; 
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
          &lt;version&gt;${springframework.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
       &lt;!-- AspectJ dependencies --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
          &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
          &lt;version&gt;${org.aspectj-version}&lt;/version&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
          &lt;artifactId&gt;aspectjtools&lt;/artifactId&gt;
          &lt;version&gt;${org.aspectj-version}&lt;/version&gt;
      &lt;/dependency&gt;
  
    &lt;/dependencies&gt;
  
     &lt;build&gt; 
      &lt;sourceDirectory&gt;src/main/java&lt;/sourceDirectory&gt;
      &lt;plugins&gt;   
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.1&lt;/version&gt;
                  &lt;!-- compile for Java 1.7 --&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${maven.compiler.source}&lt;/source&gt;
                      &lt;target&gt;${maven.compiler.target}&lt;/target&gt;
                      &lt;encoding&gt;${project.build.sourceEncoding}&lt;/encoding&gt;
                  &lt;/configuration&gt;
          &lt;/plugin&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.4&lt;/version&gt;
                  &lt;dependencies&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
                          &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
                          &lt;version&gt;${org.aspectj-version}&lt;/version&gt;
                      &lt;/dependency&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
                          &lt;artifactId&gt;aspectjtools&lt;/artifactId&gt;
                          &lt;version&gt;${org.aspectj-version}&lt;/version&gt;
                      &lt;/dependency&gt;
                  &lt;/dependencies&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;configuration&gt;
                              &lt;complianceLevel&gt;${maven.compiler.source}&lt;/complianceLevel&gt;
                              &lt;source&gt;${maven.compiler.source}&lt;/source&gt;
                              &lt;target&gt;${maven.compiler.target}&lt;/target&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  </code></pre>
  
  <ol start="2">
  <li>AspectProvider</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>@Aspect
  public class AspectProvider {   
      /**
       * This is the point cut for all get Method with @TestAnnotation annotation
       */
      @Pointcut("execution(* get*()) &amp;&amp; @annotation(aTestAnnotation)")
      public void getMethodPointcut(TestAnnotation aTestAnnotation) {}
  
  
      @Around("getMethodPointcut(aTestAnnotation)")
      public Object getConfiguration(ProceedingJoinPoint iJoinPoint, TestAnnotation aTestAnnotation) throws Throwable {
          return getValueFromISTCompositeConfiguration(iJoinPoint, aTestAnnotation);
      }
  
      private Object getValueFromISTCompositeConfiguration(final ProceedingJoinPoint iProceedingJoinPoint, TestAnnotation aTestAnnotation) throws Throwable {
  
          Object aReturnValue = null;
          if (aTestAnnotation.value() != null) {
              System.out.println("ASPECT: Returning annotation value.");
              aReturnValue = aTestAnnotation.value();
          } else {
              System.out.println("MISSING_GETTER_PROPERTY");
          }    
          if(aReturnValue == null){
               aReturnValue = iProceedingJoinPoint.proceed();
          }
          return aReturnValue;
      }
  }
  </code></pre>
  
  <ol start="3">
  <li>Annotation "TestAnnotation"</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  @Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
  @Retention(RetentionPolicy.RUNTIME)
  public @interface TestAnnotation {  
      String value();
  }
  </code></pre>
  
  <p><strong>AspectClient</strong></p>
  
  <ol>
  <li>pom.xml</li>
  </ol>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;properties&gt;
          &lt;java.version&gt;1.7&lt;/java.version&gt;
          &lt;maven.compiler.source&gt;1.7&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;1.7&lt;/maven.compiler.target&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;  
          &lt;aspectProject.version&gt;0.0.1-SNAPSHOT&lt;/aspectProject.version&gt;
          &lt;spring-framework.version&gt;4.1.2.RELEASE&lt;/spring-framework.version&gt;
          &lt;org.aspectj-version&gt;1.7.0&lt;/org.aspectj-version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;!-- Spring --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;${spring-framework.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- AspectProject dependencies --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.example.aop&lt;/groupId&gt;
              &lt;artifactId&gt;AspectProject&lt;/artifactId&gt;
              &lt;version&gt;${aspectProject.version}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
  &lt;build&gt;
    &lt;sourceDirectory&gt;src/main/java/&lt;/sourceDirectory&gt;
    &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.1&lt;/version&gt;
                  &lt;!-- compile for Java 1.7 --&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${maven.compiler.source}&lt;/source&gt;
                      &lt;target&gt;${maven.compiler.target}&lt;/target&gt;
                      &lt;encoding&gt;${project.build.sourceEncoding}&lt;/encoding&gt;
                  &lt;/configuration&gt;
             &lt;/plugin&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.4&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;showWeaveInfo&gt;true&lt;/showWeaveInfo&gt;
                      &lt;aspectLibraries&gt;
                          &lt;aspectLibrary&gt;
                               &lt;groupId&gt;com.example.aop&lt;/groupId&gt;
                               &lt;artifactId&gt;AspectProject&lt;/artifactId&gt;
                          &lt;/aspectLibrary&gt;
                      &lt;/aspectLibraries&gt;
                      &lt;complianceLevel&gt;${maven.compiler.source}&lt;/complianceLevel&gt;
                      &lt;source&gt;${maven.compiler.source}&lt;/source&gt;
                      &lt;target&gt;${maven.compiler.target}&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;dependencies&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
                          &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
                          &lt;version&gt;${org.aspectj-version}&lt;/version&gt;
                      &lt;/dependency&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
                          &lt;artifactId&gt;aspectjtools&lt;/artifactId&gt;
                          &lt;version&gt;${org.aspectj-version}&lt;/version&gt;
                      &lt;/dependency&gt;
                  &lt;/dependencies&gt;
              &lt;/plugin&gt; 
    &lt;/plugins&gt;    
  &lt;/build&gt;
  </code></pre>
  
  <ol start="2">
  <li>Service Class</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class TestService {
  
      private String value;
  
      public void internalCall() {
          System.out.println("INTERNAL_CALL :"+ getValue());
      }
  
      @TestAnnotation("RETURNED_FROM_ASPECT_CALL") 
      public String getValue() {
          return value;
      }
  
      public void setValue(String iValue) {
          this.value = iValue;
      }
  
  }
  </code></pre>
  
  <ol start="3">
  <li>Spring context.xml</li>
  </ol>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"&gt;
  
      &lt;!-- Enable AspectJ style of Spring AOP --&gt;
      &lt;context:component-scan base-package="com.example.aop.client" /&gt;
  
      &lt;aop:aspectj-autoproxy /&gt;
  
      &lt;bean name="TestService" class="com.example.aop.client.service.TestService" /&gt;
  
      &lt;!-- Configure Aspect Beans, without this Aspects advice wont execute --&gt;
      &lt;bean name="aspectProvider" class="com.example.aop.aspect.AspectProvider"/&gt; 
  
  &lt;/beans&gt;
  </code></pre>
  
  <ol start="4">
  <li>Main class</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>public class SpringMain {
  
      public static void main(String[] args) {
          ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
          TestService aTestService = ctx.getBean("TestService", TestService.class);
  
          System.out.println("EXTERNAL_CALL: "+aTestService.getValue());
          aTestService.internalCall();        
          ctx.close();
      }
  
  }
  </code></pre>
  
  <p><strong>OUTPUT:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>ASPECT: Returning annotation value. 
  EXTERNAL_CALL:RETURNED_FROM_ASPECT_CALL 
  INTERNAL_CALL: **null**
  </code></pre>
  
  <p>Expected:</p>
  
  <pre class="lang-none prettyprint-override"><code>ASPECT: Returning annotation value.
  EXTERNAL_CALL: RETURNED_FROM_ASPECT_CALL
  INTERNAL_CALL: **RETURNED_FROM_ASPECT_CALL**
  </code></pre>
  
  <p>Please advice in case if I am missing any entry or required to change configuration.Thanks in advance for your valuable time.</p>