title: Within vs target pointcut designator in Spring AOP
body: <p>I couldn't understand different between within and target pointcut designator.</p>
  
  <p>Look at the example:</p>
  
  <pre><code>@Component
  public interface Icamera {
      public void snap() throws Exception;
  }
  
  @Component
  class Camera implements Icamera {
      public void snap() throws Exception {
          System.out.println("SNAP!");
      }
  }
  
  @Aspect
  @Component
  public class Logger {
  
      **@Pointcut("within(com.test.aop.Icamera)")**
      public void cameraSnap() {
      }
  
      @Before("cameraSnap()")
      public void beforeAdvice() {
          System.out.println("Before advice ...");
      }
  
      @After("cameraSnap()")
      public void afterAdvice() {
          System.out.println("After advice ...");
      }
  
      public static void main(String[] args) throws Exception {
          ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
          Icamera camera = context.getBean(Icamera.class);
          camera.snap();
      }
  
  }
  </code></pre>
  
  <p>The output is:
  SNAP!
  but when you use target instead of within, the output is:
  Before advice ...
  SNAP!
  After advice ...</p>