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?
Thanks to @Dave Newton giving me the clue. In order for me to inject
theProxyfrom the web, for my case, it was JSF, I have to put following code infaces-config.xml.And the put in the listener provided by @tom as well into
web.xml.