title: How to load Spring AOP into web app?
body: <p>I was trying to implement Spring AOP in web app. Unfortunately all the sample code I found on the Web are console app. I was running out of clue how could I do it in web app?</p>
  
  <p>In web.xml file, I load the applicationContext.xml like this:</p>
  
  <pre><code>&lt;context-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>In applicationContext.xml file, I have ProxyFactoryBean defined like this:</p>
  
  <pre><code>&lt;bean id="theBo" class="my.package.TheBo"&gt;
    ...
  &lt;/bean&gt;    
  &lt;bean id="theProxy" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;
        &lt;property name="proxyInterfaces"&gt;
          &lt;list&gt;
              &lt;value&gt;my.package.ITheBo&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="target" ref="theBo"/&gt;
      &lt;property name="interceptorNames"&gt;
          &lt;list&gt;
              &lt;value&gt;loggingBeforeAdvice&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>My situation now is I don't know where is the best place to put this code:</p>
  
  <pre><code>ApplicationContext context = new ClassPathXmlApplicationContext("WEB-INF/applicationContext.xml");
  theBo = (ITheBo) context.getBean("theProxy");
  </code></pre>
  
  <p>If this was a console app, I would rather put it in the main(), but how could I do it in web app?</p>