You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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 type

scope

no

the scope of the bean; must be either default, singleton, request, session, thread

static

no

whether to inject static methods or not; shouldn't be true when the type is specified

optional

no

whether the bean is optional or not

Sample usage

Bean Example (struts.xml)
<struts>

  <bean type="com.opensymphony.xwork2.ObjectFactory" name="myfactory" class="com.company.myapp.MyObjectFactory" />
  
  ... 

</struts>
  • No labels