2005-12-01
webwork和spring的结合 Use SpringObjectFactory
//webwork的文档中自带
The xwork-optional package from dev.java.net contains a module xwork-spring that contains all the necessary code to use Spring in WebWork. It contains primarily a SpringObjectFactory to wire up the dependencies for an Action before passing it to WebWork. Each action should be configured within a Spring application context as a prototype (because WebWork assumes a new instance of a class for every action invocation). Specify something like this in applicationContext.xml:
[code:1]<bean name="some-action" class="fully.qualified.class.name" singleton="false">
<property name="someProperty"><ref bean="someOtherBean"/></property>
</bean>[/code:1]
and in xwork.xml:
[code:1]<action name="myAction" class="some-action">
<result name="success">view.jsp</result>
</action>[/code:1]
Notice that the WebWork Action's class name some-action is the bean name defined in the Spring application context.
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. This method assumes that the Spring application context has already been configured. Add the following to web.xml:
[code:1]<!-- This needs to be after Spring ContextLoaderListener -->
<listener>
<listener-class>com.opensymphony.xwork.spring.SpringObjectFactoryListener</listener-class>
</listener>[/code:1]
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:1]<bean id="spring-object-factory" class="com.opensymphony.xwork.spring.SpringObjectFactory" init-method="initObjectFactory"/>[/code:1]Note: The second option should work when only using Xwork (as compared to XW and WW2).
The xwork-optional package from dev.java.net contains a module xwork-spring that contains all the necessary code to use Spring in WebWork. It contains primarily a SpringObjectFactory to wire up the dependencies for an Action before passing it to WebWork. Each action should be configured within a Spring application context as a prototype (because WebWork assumes a new instance of a class for every action invocation). Specify something like this in applicationContext.xml:
[code:1]<bean name="some-action" class="fully.qualified.class.name" singleton="false">
<property name="someProperty"><ref bean="someOtherBean"/></property>
</bean>[/code:1]
and in xwork.xml:
[code:1]<action name="myAction" class="some-action">
<result name="success">view.jsp</result>
</action>[/code:1]
Notice that the WebWork Action's class name some-action is the bean name defined in the Spring application context.
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. This method assumes that the Spring application context has already been configured. Add the following to web.xml:
[code:1]<!-- This needs to be after Spring ContextLoaderListener -->
<listener>
<listener-class>com.opensymphony.xwork.spring.SpringObjectFactoryListener</listener-class>
</listener>[/code:1]
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:1]<bean id="spring-object-factory" class="com.opensymphony.xwork.spring.SpringObjectFactory" init-method="initObjectFactory"/>[/code:1]Note: The second option should work when only using Xwork (as compared to XW and WW2).
发表评论
- 浏览: 51324 次
- 来自: 大连

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
Velocity用户手册---中文 ...
现在用velocity的少了把,不过类似的模板可是越来越多了
-- by airport -
Velocity用户手册---中文 ...
雪中送炭,收了,谢了!!!
-- by chamborghini -
Velocity用户手册---中文 ...
GOOD!
-- by iRoyce -
Velocity用户手册---中文 ...
谢谢!!非常好!!
-- by wxl4040 -
整合File-Column和Rmagic ...
我可以用rmagick和file_column.但是当我点edit编辑先前存在的 ...
-- by mrunix






评论排行榜