title: Spring AOP - pointcut/interceptor not called
body: <p>I have defined the following interceptor: </p>
  
  <pre><code>@Aspect
  public class OpenSessionInRequestInterceptor {
  
      private Log log = LogFactory.getLog(getClass());
  
      @Autowired
      private SessionFactory sessionFactory;
  
      public OpenSessionInRequestInterceptor() {
  
      }
  
      @Around("@annotation(com.sc2.master.aop.hibernate.OpenSession)")
      public Object processAround(ProceedingJoinPoint pjp) throws Throwable {
          log.info("Opening Hibernate Session in method "+pjp.getSignature());
          Session session = SessionFactoryUtils.getSession(sessionFactory, true);
          TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
  
          Object ret = pjp.proceed();
  
          session.close();
          TransactionSynchronizationManager.unbindResource(sessionFactory);
  
          log.info("Closing Hibernate Session in method "+pjp.getSignature());
  
          return ret;
      }
  
  }
  </code></pre>
  
  <p>When I execute the following piece of code in a spring test</p>
  
  <pre><code>    @OpenSession
      public void call() {
          BusinessCustomer customer = (BusinessCustomer) this.customerDao.loadAll().get(0);
          System.out.println(customer.getContacts().size());
      }
  </code></pre>
  
  <p>the aspect method is called. To start the test my test case class looks as follows:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations={"file:WebContent/WEB-INF/applicationContext.xml"})
  @Transactional
  </code></pre>
  
  <p>However, when I have a method annotated with @OpenSession and deploy the application on my Tomcat server, the interceptor method is not called.</p>
  
  <p>The application context definition looks as follows:</p>
  
  <pre><code>&lt;aop:aspectj-autoproxy proxy-target-class="true"&gt;
  &lt;/aop:aspectj-autoproxy&gt;
  
  &lt;bean id="openSessionInRequestInterceptor" class="OpenSessionInRequestInterceptor"&gt;&lt;/bean&gt;
  </code></pre>
  
  <p>I can absolutely not figure out, why AOP does not work when deployed on the tomcat. I hope you have some ideas.</p>
  
  <p><strong>Solution</strong> I found the solution. I places my aop configuration in the applicationContext.xml, but this will not work. I placed the configuration in the application-servlet.xml and now everything is fine. Has someone an idea why?</p>