Struts uses an internal Dependency Injection framework, named Guice, to load key framework beans. This allows any piece of the framework to be replaced, extended, or removed in a standard, consistent way. Plugins, in particular, leverage this capability to extend the framework to provide support for third-party libraries like Spring or Sitemesh. Therefore, the common Struts application most likely won't need to interact with this particular configuration element.
Beans
The bean element has one required attribute, class
, which specifies the Java class to be created or manipulated. A bean can either be defined so that it is created by Guice to be injected into internal Struts objects, or it can define the static
attribute to tell Guice to only inject its static methods. The former use is generally accompanied by the type
attribute, which tells Guice which interface this object implements. The latter use is good for allowing objects not created by Guice to receive framework constants.
Attribute |
Required |
Description |
---|---|---|
class |
yes |
the name of the bean class |
type |
no |
the primary Java interface this class implements |
name |
no |
the unique name of this bean; must be unique among other beans that specify the same |
scope |
no |
the scope of the bean; must be either |
static |
no |
whether to inject static methods or not; shouldn't be |
optional |
no |
whether the bean is optional or not |
Sample usage
<struts> <bean type="com.opensymphony.xwork2.ObjectFactory" name="myfactory" class="com.company.myapp.MyObjectFactory" /> ... </struts>