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.(插件尤其通过扩展框架去支持第三方的类库比如Spring或者Sitemesh类来平衡这种能力。)
 
Most applications won't need to extend the Bean Configuration.(大多的应用程序将不需要去拓展Bean配置)
 
Beans
The bean element has one required attribute, class, which specifies the Java class to be created or manipulated. (bean元素有一个必须的属性,class,class指定了要创建和控制的特定的java class)A bean can either
1.be created by the framework's container and injected into internal framework objects, or
2.have values injected to its static methods(一个bean可以由框架的容器来创建,也可以被插入框架内部对象,或者把值插入到静态方法中。)
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.(要让对象使用值注入必须去定义它的static属性。)
 
Attribute Required Description
class yes the name of the bean class(bean类的名字)
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(这个bean独一无二的名字,必须在所有指定了相同类型的bean中是独一无二的)
scope no the scope of the bean; must be either defaultsingletonrequestsessionthread(bean的范围,必须是 defaultsingletonrequestsessionthread  
static no whether to inject static methods or not; shouldn't be true when the type is specified(是否是静态注入方法,当type被指定它不能是true)
optional no whether the bean is optional or not(这个bean是否是可选的)

 

Sample usage

Bean Example (struts.xml)

    
    
    
    
  1. <struts> 
  2.  
  3.   <bean type="com.opensymphony.xwork2.ObjectFactory" name="myfactory" class="com.company.myapp.MyObjectFactory" /> 
  4.    
  5.   ...  
  6.  
  7. struts> 

111