Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Another advantage of the SpringObjectFactory approach is that it can also be used to load interceptors using the same sort of logic. If the interceptor is stateless, then it's possible to create the interceptor as a singelton instance, but otherwise it's best to create it as a Spring prototype.
In order to be used, the default ObjectFactory that WebWork uses should be replaced with an instance of the SpringObjectFactory. There are two different ways to accomplish this. The first method is to use the ContextListener in the xwork-optional package ships with a ContextListener that does this, assuming that . This method assumes that the Spring application context has already been configured. Add the following to web.xml:

...

Note: this is actually a XWork configuration but for simplicity, I just assume WebWork.

The second method is to call the initObjectFactory method on com.opensymphony.xwork.spring.SpringObjectFactory. The easiest way to do this is to have Spring's application configure and supply the aforementioned method as the "init-method". Add the following to your applicationContext.xml:

Code Block
xml
xml

<bean id="spring-object-factory" class="com.opensymphony.xwork.spring.SpringObjectFactory" init-method="initObjectFactory"/>

Note: The second option should work when only using Xwork (as compared to XW and WW2).