title: AOP Spring @AfterReturning not working as expected
body: <p>I am learning AOP spring and trying out some examples. Regarding @AfterReturning,what i have understand is that the method is called only if the target is returned successfully and which match the pointcut. However in my case as shown below i have a pointcut that defines all method that returns a String only but it is calling all the void method and also the method which return a String.</p>
  
  <p>My Advice:</p>
  
  <pre><code>@AfterReturning(value= "execution(*  com.aop..CustomerServiceImpl.*(..))",
          returning= "string")
  public void returnStringPointcut(JoinPoint joinPoint,String string){
  
      System.out.println("logAfter() is running!");
      System.out.println("String : " + string);
      System.out.println("hijacked : " + joinPoint.getSignature().getName());
      System.out.println("******");
  
  }
  </code></pre>
  
  <p>Please find below my Impl class below:</p>
  
  <pre><code>public void addCustomer() {
      // TODO Auto-generated method stub
  
  }
  
  public String getCustomer() {
      // TODO Auto-generated method stub
      return "string";
  }
  
  public boolean deleteCustomer() {
      // TODO Auto-generated method stub
      return false;
  }
  public void addCustomerAppended() {
      // TODO Auto-generated method stub
  
  }
  
  public void deleteCustomerVoid() {
      // TODO Auto-generated method stub
      //return false;
  }
  </code></pre>
  
  <p>Please find below my MainApp class:</p>
  
  <pre><code>public class App {
      public static void main(String[] args)
  
      {
          ApplicationContext context = new ClassPathXmlApplicationContext(
                  "Spring-Customer.xml");
  
          CustomerService cs =  context.getBean("customerBo", CustomerService.class);
          cs.addCustomer();
          cs.addCustomerAppended();
          cs.deleteCustomer();
          cs.deleteCustomerVoid();
          cs.getCustomer();
  
  
      }
  }
  </code></pre>
  
  <p>I was expecting that only  getCustomer() will be called since it is the only one that returns a string but instead i get the following output in my console when i run the application:</p>
  
  <pre><code>logAfter() is running!
  String : null
  hijacked : addCustomer
  ******
  logAfter() is running!
  String : null
  hijacked : addCustomerAppended
  ******
  logAfter() is running!
  String : null
  hijacked : deleteCustomerVoid
  ******
  logAfter() is running!
  String : string
  hijacked : getCustomer
  ******
  </code></pre>
  
  <p>Please find my pom.xml below:</p>
  
  <pre><code>&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;com.aop.spring&lt;/groupId&gt;
      &lt;artifactId&gt;SpringAopOnly&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;SpringAopOnly&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
      &lt;properties&gt;
          &lt;spring.version&gt;3.0.5.RELEASE&lt;/spring.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.8.2&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Spring 3 dependencies --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Spring AOP  --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
              &lt;dependency&gt;
              &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
              &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
              &lt;version&gt;1.6.11&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
              &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
              &lt;version&gt;1.6.11&lt;/version&gt;
              &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Please find my config file below:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:aop="http://www.springframework.org/schema/aop"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "&gt;
  
      &lt;!-- &lt;aop:aspectj-autoproxy /&gt;  --&gt;
      &lt;aop:aspectj-autoproxy&gt;
      &lt;aop:include name ="logAspect" /&gt;
      &lt;/aop:aspectj-autoproxy&gt;
  
      &lt;bean id="customerBo" class="com.aop.impl.CustomerServiceImpl" /&gt;
  
      &lt;!-- Aspect --&gt;
      &lt;bean id="logAspect" class="com.aop.aspect.CustomerAspect" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Any idea why  it is calling the void method please?</p>
  
  <p>I have also tried to change the afterReturning from String to boolean then i get the expected result that is only  deleteCustomer is called since it returns a boolean.</p>
  
  <p>Thanks a lot in advance for response.</p>