title: Spring AOP in controllers
body: <p>I have a spring project, and am trying to implements AOP in controllers.</p>
  
  <p>I add these lines in my applicationContext.xml:</p>
  
  <pre><code>&lt;aop:aspectj-autoproxy/&gt;
  &lt;bean id="homeController" class="package.domain.HomeController" /&gt;
  &lt;bean id="logAspect" class="package.aspect.LoggingAspect" /&gt;
  </code></pre>
  
  <p>My aspect class is this:</p>
  
  <pre><code>@Aspect
  @Component
  public class LoggingAspect {
  
  
      protected final Log logger = LogFactory.getLog(getClass());
  
      @Pointcut("execution( * package.web.HomeController.home(..) )")
      public void poincut() {
      }
  
      @Before("poincut()")
      public void before(){
          System.out.println("before");
      }
  
      @AfterReturning("poincut()")
      public void after(){
          System.out.println("after");
      }
  
      @AfterThrowing("poincut()")
      public void AfterThrowing(){
          System.out.println("AfterThrowing");
      }
  
  }
  </code></pre>
  
  <p>and my controller is this:</p>
  
  <pre><code>@RequestMapping(value = "/home.htm")
      public ModelAndView home(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
  
          ....
  
          return new ModelAndView("home", "model", model);
      }
  </code></pre>
  
  <p>All likes good, no errors and this message:</p>
  
  <pre><code>DEBUG: org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory - Found AspectJ method: public void package.aspect.LoggingAspect.before()
  DEBUG: org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory - Found AspectJ method: public void package.aspect.LoggingAspect.after()
  DEBUG: org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory - Found AspectJ method: public void package.aspect.LoggingAspect.AfterThrowing()
  </code></pre>
  
  <p>If change my pointcut and use the next line it works, but when I choose a controller fails:</p>
  
  <pre><code>@Pointcut("execution( * *(..) )")
  </code></pre>
  
  <p>Thanks!!</p>