title: Java - Spring AOP Pointcut not working
body: <p>Can someone pinpoint what am I doing wrong? How can I make my Aspect run?</p>
  
  <p>I have written this code following some examples:</p>
  
  <pre><code>@Aspect
  public class MethodLogger {
  
      private Logger log = Logger.getLogger(getClass().getName());
  
      @Pointcut("execution(* setHeight(..))")
      public void log(JoinPoint point) {
          log.info(point.getSignature().getName() + " called...");
  
      }
  }
  </code></pre>
  
  <p>My simple test class:</p>
  
  <pre><code>public class ChairImpl implements Chair {
      int height;
      public ChairImpl(){}
  
      public int getHeight() {
          return height;
      }
      public void setHeight(int height) {
          this.height = height;
      }
  
  
  }
  </code></pre>
  
  <p>My Spring xml config:</p>
  
  <pre><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:p="http://www.springframework.org/schema/p"
          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-3.0.xsd 
              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
              http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
          default-destroy-method="destroy"
          default-init-method="afterPropertiesSet"
          default-autowire="byName"
  &gt;
  
  &lt;aop:aspectj-autoproxy&gt;
          &lt;aop:include name="MethodLogger"/&gt;
      &lt;/aop:aspectj-autoproxy&gt;
  
      &lt;bean id="logger1" class="lab.MethodLogger"/&gt;
  
      &lt;bean id="chair1" 
      class="lab.test.ChairImpl"
      &gt;
          &lt;property name="height" value="10"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>And my main method:</p>
  
  <pre><code>public class Main {
      public static void main(String[] args){
          ApplicationContext context = new ClassPathXmlApplicationContext("spec.xml");
          ((AbstractApplicationContext) context).close();
  
      }
  }
  </code></pre>
  
  <p>So before running my project, Eclipse gives me this error(it marks red <code>void</code> word for <code>log</code> method):</p>
  
  <pre><code>Pointcuts without an if() expression should have an empty method body
  </code></pre>
  
  <p>When I run, my program runs without errors, because it looks like <code>log</code> method never ran. So how could I fix it so it would run and output log? I tried simply to print <code>test text</code> from that method, but it never does, so it means it never runs. What am I missing here?</p>
  
  <p>In documentation it only writes vague examples like:</p>
  
  <pre><code>@Pointcut("execution(* transfer(..))")// the pointcut expression
  private void anyOldTransfer() {}// the pointcut signature
  </code></pre>
  
  <p>But I find it hard to understand how to actually use it to see results.</p>