Bean Configuration


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. (2つ目の目的:値注入は、コンテナで作成されたオブジェクトではなくフレームワークを受け入れることができる定数です.)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 default,singleton,request,session,thread(beanの範囲はdefault,singleton,request,session,thread)
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