考虑像这样的一行代码
AutomobileDriver ad=(AutomobileDriver)appContext.getBean("increaseSpeed");
Run Code Online (Sandbox Code Playgroud)
假设有一个IncreaseSpeed继承自AutomobileDriver类的类
怎么getBean办?这个的主要功能是什么?
用“简单的外行术语”来说:
这假设 Spring 被告知创建一个对象实例(可能在 XML 配置文件中),该实例(由 Spring)标识为 id“increaseSpeed”,并且具有AutomobileDriver.
您要求 Spring 上下文引用 (a) 默认情况下先前创建的对象(这称为单例)或 (b) 该对象的新实例(原型)。
| 归档时间: |
|
| 查看次数: |
1342 次 |
| 最近记录: |