1.3.2.1.Instantiation with a Constructor (通过构造函数进行实例化)

 Spring Framework Documentation (5.3.10)

Core

IoC Container, Events, Resources, i18n, Validation, Data Binding, Type Conversion, SpEL, AOP.

   Core Technologies

1. The IoC Container

1.1. Introduction to the Spring IoC Container and Beans(Spring IoC容器和bean简介)

1.2. Container Overview (容器概览)

1.3. Bean Overview (Bean概览)

1.3.1. Naming Beans (Bean命名)

1.3.1.1Aliasing a Bean outside the Bean Definition 在Bean定义外指定Bean别名

1.3.2. Instantiating Beans实例化bean

1.3.2.1.Instantiation with a Constructor (通过构造函数进行实例化)

1.3.2.2. Instantiation with a Static Factory Method (通过静态工厂方法进行实例化)

1.3.2.3. Instantiation by Using an Instance Factory Method (使用实例工厂方法进行实例化)

1.3.2.4. Determining a Bean’s Runtime Type(确定Bean的运行时类型)


下载此文档精编完整版

 No.内容下载地址文档内容目录
1中英双语精编版 第一部分PDF下载内容目录
2中英双语精编版 第二部分PDF下载内容目录
3中文精编版 第一部分PDF下载内容目录
4中文精编版 第二部分PDF下载内容目录

更多章节内容,请点击查看:  Core Technologies


1.3.2.1.Instantiation with a Constructor (通过构造函数进行实例化)

When you create a bean by the constructor approach, all normal classes are usable by and compatible with 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. However, depending on what type of IoC you use for that specific bean, you may need a default (empty) constructor.

当您通过构造函数方法创建bean时,所有普通类(normal classe)都可以由Spring使用,并且与Spring兼容。也就是说,正在开发的类不需要实现任何特定的接口,也不需要以特定的方式进行编写代码。只需指定bean类就足够了。但是,根据您对特定bean使用的IoC类型,您可能需要一个默认的(空)构造函数。

The Spring IoC container can manage virtually any class you want it to manage. It is not limited to managing true JavaBeans. 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. You can also have more exotic non-bean-style classes in your container. 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.

Spring IoC容器实际上可以管理您希望它管理的任何类。它不仅仅限于管理真正的JavaBean。大多数Spring用户更喜欢这样的JavaBean:只有一个默认(无参数)构造函数,并根据容器中的属性建模适当的settergetter。您的容器中还可以有其他特殊的非bean样式的类。例如,如果您需要使用一个完全不符合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.

构造对象后,关于向构造函数提供参数(如果需要)和设置对象实例属性的机制的详细信息,请参阅注入依赖项(Injecting Dependencies)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

月满闲庭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值