Question: 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?

In web.xml file, I load the applicationContext.xml like this:

```
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

```

In applicationContext.xml file, I have ProxyFactoryBean defined like this:

```
<bean id="theBo" class="my.package.TheBo">
  ...
</bean>    
<bean id="theProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
      <property name="proxyInterfaces">
        <list>
            <value>my.package.ITheBo</value>
        </list>
    </property>
    <property name="target" ref="theBo"/>
    <property name="interceptorNames">
        <list>
            <value>loggingBeforeAdvice</value>
        </list>
    </property>
</bean>

```

My situation now is I don't know where is the best place to put this code:

```
ApplicationContext context = new ClassPathXmlApplicationContext("WEB-INF/applicationContext.xml");
theBo = (ITheBo) context.getBean("theProxy");

```

If this was a console app, I would rather put it in the main(), but how could I do it in web app?

Answer: 
You do not need the following piece of code to load the context:

```
ApplicationContext context = new ClassPathXmlApplicationContext("WEBINF/applicationContext.xml");
theBo = (ITheBo) context.getBean("theProxy");

```

You have to add the `ContextLoaderListener` to your `web.xml` file:

```
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

```

Now when your web application starts the contexts declared in the `<context-param>` contextConfigLocation are loaded. In your case '/WEB-INF/applicationContext.xml'.

If you need your context in a specific class you can implement the `ApplicationContextAware` interface to retrieve it.

For the rest, your webapp is now a basic spring application where you can wire your classes as you would normally do.
Thanks to @Dave Newton giving me the clue. In order for me to inject `theProxy` from the web, for my case, it was JSF, I have to put following code in `faces-config.xml`.

```
<application>
   <variable-resolver>
      org.springframework.web.jsf.DelegatingVariableResolver
   </variable-resolver>
</application>

<managed-bean>
   <managed-bean-name>theAction</managed-bean-name>
   <managed-bean-class>org.huahsin68.theAction</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
         <property-name>theBo</property-name>
            <value>#{theProxy}</value>
      </managed-property>
</managed-bean>

```

And the put in the listener provided by @tom as well into `web.xml`.