IOC (4) in Webwork

zhaozj2021-02-16  76

4, configure components in Webwork and XWork

(1) Configure Web.xml

To configure webwork component management, you need to add the following lines in Web.xml:

container

com.opensymphony.webwork.lifecycle.requestlifecyclefilter

container

*. action

com.opensymphony.webwork.lifecycle.SessionLifeCyleCleListener

com.opensymphony.webwork.lifecycle.ApplicationLifeCyleCleListener

These settings allow WebWork to manage components within the Application, Session, and Request ranges. Note that even if your application has no need for a certain range, it is also included.

(2) Configure xwork.xml

ComponentInterceptor is used to apply the IOC mode to the an action of the XWork. Therefore, must be used in xwork.xml to declare the ComponentInterceptor:

Class = "com.opensymphony.xwork.interceptor.component.componentinterceptor" />

If you want to apply IOC to an object other than Action, you need to use ComponentManager directly.

In addition, ComponentInterceptor is already in Webwork's DefaultStack. So if you apply DefaultStack in xwork.xml, it already contains ComponentInterceptor.

(3) Configure Components.xml

Components.xml is used to define the available components. The components specified here will be loaded into the XWork's ComponentManager, which is valid for the action that is specified Enabler instance. Components.xml must be placed in a web-inf / class directory.

The following example is configured in Components.xml, which is the SESSION, which will be passed to the object that implements the CounteraWare interface:

session

com.opensymphony.WebWork.example.counter.counter

com.opensymphony.webwork.example.counter.counteraware

There are three properties for each Component:

l Scope: Component Lifecycle Range, Valid Value Applaction, Session and Request

l Class: Component Classification

l Enabler: Enabler: Enabler class or interface (recommended by the latter), any action as an instance of the Enabler instance will be passed

转载请注明原文地址:https://www.9cbs.com/read-13740.html

New Post(0)