4.IOC创建对象的过程
- 使用无参构造创造
设定为有参后,就会报错!
对象在被注册进去的时候,就被实例化了,直接使用就好。
5.IO注入
(1)前面的构造器注入
(2)set注入
构造注入对象之间的关系为组合
set注入的对象之间的关系为聚合
(3)p命名空间注入
- 使用set方式注入
(4)c命名空间注入
- 使用构造器方式注入,开启构造器才能用
HelloSpring(String name){
this.name=name;
}
HelloSpring(){
}
注意导入头文件
xmlns:p = "http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
6.作用域
ScopeDescription
(Default) Scopes a single bean definition to a single object instance for each Spring IoC container.
Scopes a single bean definition to any number of object instances.
Scopes a single bean definition to the lifecycle of a single HTTP request. That is, each HTTP request has its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext
.
Scopes a single bean definition to the lifecycle of an HTTP Session
. Only valid in the context of a web-aware Spring ApplicationContext
.
Scopes a single bean definition to the lifecycle of a ServletContext
. Only valid in the context of a web-aware Spring ApplicationContext
.
Scopes a single bean definition to the lifecycle of a WebSocket
. Only valid in the context of a web-aware Spring ApplicationContext
.
- 单例
**
- 原型
Original: https://www.cnblogs.com/lumanmanqixiuyuanxi/p/16521971.html
Author: 路漫漫qixiuyuanxi
Title: [spring]spring注入属性值的两种方式以及作用域
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/574473/
转载文章受原作者版权保护。转载请注明原作者出处!