Internally, the framework uses its own dependency injection
container. The container loads key framework objects, so that any piece
of the framework can 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.
Most applications won't need to extend the Bean Configuration.
Beans
The bean element has one required attribute, class, which specifies the Java class to be created or manipulated. A bean can either
- be created by the framework's container and injected into internal framework objects, or
被框架的容器創建,并注入到內部框架的對象,或者 2.have values injected to its static methods
把值注入到靜態方法中
The first use, object injection, is generally accompanied by the type attribute, which tells the container which interface this object implements.
前者,對象注入,通常設置了type屬性,告訴容器對象擴張了哪個接口。
The second use, value injection, is good for allowing objects not
created by the container to receive framework constants. Objects using
value inject must define the the static attribute.
后者,值注入,有利于允許對象不被容器創建來接收框架常量。對象用值注入必須定義靜態屬性。
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
<struts>
<bean type="com.opensymphony.xwork2.ObjectFactory" name="myfactory" class="com.company.myapp.MyObjectFactory" />
...
</struts>