• Typically, to specify the bean class to be constructed in the case where the container itself directly creates the bean by calling its constructor reflectively, somewhat equivalent to Java code with the new operator.
•通常,在容器本身通过反射调用其构造函数直接创建bean的情况下,指定要构造的bean类,在某种程度上相当于使用new操作符的Java代码。【全句机翻】
• To specify the actual class containing the static factory method that is invoked to create the object, in the less common case where the container invokes a static factory method on a class to create the bean.
•指定包含被调用来创建对象的静态工厂方法的实际(已存在的)类,在不太常见的情况下,容器在类上调用静态工厂方法来创建bean。【全句机翻】
The object type returned from the invocation of the static factory method may be the same class or another class entirely.
从静态工厂方法返回的对象可能额是同一个类或者完全不同的类。
Inner class names
内部类names属性
If you want to configure a bean definition for a static nested class, you have to use the binary name of the nested class.
如果你想要为一个静态内部类配置一个类定义,你必须使用内部类的二进制名字。
For example, if you have a class called SomeThing in the com.example package, and this SomeThing class has a static nested class called OtherThing, the value of the class attribute on a bean definition would be com.example.SomeThing$OtherThing.
Notice the use of the $ character in the name to separate the nested class name from the outer class name.
例如,你在com.example包下有一个叫SomeThing的类,然后这个叫SomeThing的类由一个静态内部类叫OtherThing,在bean定义中其class属性的值将会是com.example.SomeThing$OtherThing.
Notice the use of the $ character in the name to separate the nested class name from the outer class name.
为了从外部类名中分割内部类名,注意$字符的使用在name属性中的使用
Instantiation with a Constructor
使用构造器初始化
When you create a bean by the constructor approach, all normal classes are usable by and compatible with Spring.
当你使用构造方法创造一个bean时,所有普通类都可以被Spring使用和兼容。【没看懂】
That is, the class being developed does not need to implement any specific
interfaces or to be coded in a specific fashion.
也就是说,被开发的类不需要实习那任何特殊几口或者以特殊的形式编码。
Simply specifying the bean class should suffice.
简单地指定bean类就足够了。
However, depending on what type of IoC you use for that specific bean, you may need a default (empty) constructor.
然而,根据你采用控制反转的形式指定bean,你可能需要一个默认(空)的构造器。
The Spring IoC container can manage virtually any class you want it to manage.
SpringIoC容器几乎可以管理任何你想要它管理的类。
It is not limited to managing true JavaBeans.
管理真正(实例?)JavaBean是不受限制的。
Most Spring users prefer actual JavaBeans with only a default (no- argument) constructor and appropriate setters and getters modeled after the properties in the
container.
大多数Spring框架的使用者更喜欢在容器里只有默认无参构造方法和在属性周恰当的setters和getters方法的JavaBeans。
You can also have more exotic non-bean-style classes in your container.
你也可以有更多独特的non-bean-styles类在你的容器里。【不知道是什么风格】
If, for example, you need to use a legacy connection pool that absolutely does not adhere to the JavaBean specification, Spring can manage it as well.
假设,例如你需要使用一个过时的连接池它完全不遵循JavaBean风格,Spring同样可以管理它。
With XML-based configuration metadata you can specify your bean class as follows:
基于XML配置元数据你可以指定你的Bean类像这样:
<bean id="exampleBean" class="examples.ExampleBean"/>
<bean name="anotherExample" class="examples.ExampleBeanTwo"/>
For details about the mechanism for supplying arguments to the constructor (if required) and setting object instance properties after the object is constructed, see Injecting Dependencies.
有关(如有必要)有参构造器和在对象被构造后set如对象实例属性的机制详情,请看依赖注入。
Instantiation with a Static Factory Method
使用一个静态工厂方法实例化
When defining a bean that you create with a static factory method, use the class attribute to specify the class that contains the static factory method and an attribute named factory-method to specify the name of the factory method itself.
当定义一个你使用静态工厂方法创造的bean时,使用class属性去指定一个包含静态工厂方法和一个名为工厂—方法指定工厂方法本身的类【有点拗口】
You should be able to call this method (with optional arguments, as described later) and return a live object, which subsequently is treated as if it had been created through a constructor.
你应该调用这个方法(带有可选参数,像接下来描述得那样)然后返回一个live的对象,
接下来它会和通过构造器生成的对象一样被处理。
One use for such a bean definition is to call static factories in legacy code.
这样的bean定义的其中一种用途时在过时代码中掉用静态方法。
The following bean definition specifies that the bean be created by calling a factory method.
下列的bean定义指定的bean是那些被调用工厂方法所创建的。
The definition does not specify the type (class) of the returned object, only the class containing the factory method.
这个bean定义并没有指定返回对象的类型,共厂方法只含有类属性。
In this example, the createInstance() method must be a static method.
在这个例子, createInstance() 方法必须是一个静态方法
The following example shows how to specify a factory method:
以下的例子展示了如何指定一个工厂方法:
<bean id="clientService"
class="examples.ClientService"
factory-method="createInstance"/>