海南建站中心,网站开发离线下载报表,花生壳域名直接做网站,怎样做免费的网站推广目录
构造器注入
set注入
拓展注入
bean的作用域
Singleton
Prototype Dependency Injection 依赖 : 指Bean对象的创建依赖于容器 . Bean对象的依赖资源 . 注入 : 指Bean对象所依赖的资源 , 由容器来设置和装配 .
构造器注入
具体实现#xff1a;SpringIOC创建对象的…目录
构造器注入
set注入
拓展注入
bean的作用域
Singleton
Prototype Dependency Injection 依赖 : 指Bean对象的创建依赖于容器 . Bean对象的依赖资源 . 注入 : 指Bean对象所依赖的资源 , 由容器来设置和装配 .
构造器注入
具体实现SpringIOC创建对象的方式_March€的博客-CSDN博客
set注入
要求被注入的属性 , 必须有set方法 , set方法的方法名由set 属性首字母大写 , 如果属性是boolean类型 , 没有set方法 , 是 is....
测试domain类
Address.java
public class Address {private String address;public String getAddress() {return address;}public void setAddress(String address) {this.address address;}
}
Student.java
package com.kuang.pojo;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class Student {private String name;private Address address;private String[] books;private ListString hobbys;private MapString,String card;private SetString games;private String wife;private Properties info;public void setName(String name) {this.name name;}public void setAddress(Address address) {this.address address;}public void setBooks(String[] books) {this.books books;}public void setHobbys(ListString hobbys) {this.hobbys hobbys;}public void setCard(MapString, String card) {this.card card;}public void setGames(SetString games) {this.games games;}public void setWife(String wife) {this.wife wife;}public void setInfo(Properties info) {this.info info;}public void show(){System.out.println(name name ,address address.getAddress() ,books);for (String book:books){System.out.print(book\t);}System.out.println(\n爱好:hobbys);System.out.println(card:card);System.out.println(games:games);System.out.println(wife:wife);System.out.println(info:info);}
}
1.常量注入
bean idstudent classcom.ffyc.domain.Studentproperty namename value张三/property
/bean
2.bean注入
这里的值是一个引用ref
bean idaddress classcom.ffyc.domain.Addressproperty nameaddress value西安/
/bean
bean idstudent classcom.ffyc.domain.Studentproperty namename value张三/property nameaddress refaddress/
/bean
3.数组注入
property namebooksarrayvalue西游记/valuevalue红楼梦/valuevalue水浒传/value/array
/property
4.List注入
property namehobbyslistvalue唱歌/valuevalue跳舞/value/list
/property 5.map注入
property namecardmapentry key电话 value123456/entryentry key账户 value1111/entry/map
/property
6.set注入
property namegamessetvaluelol/valuevalue王者荣耀/value/set/property
7.Null注入
property namewifenull/null
/property
8.properties注入
property nameinfopropsprop key学号123/propprop key性别男/prop/props
/property 测试类 拓展注入
1、P命名空间注入 : 需要在头文件中导入约束文件
导入约束 : xmlns:phttp://www.springframework.org/schema/p
!--P(属性: properties)命名空间 , 属性依然要设置set方法--
bean iduser classcom.ffyc.domain.User p:name张三/
2、c 命名空间注入 : 需要在头文件中导入约束文件
导入约束 : xmlns:chttp://www.springframework.org/schema/c
!--C(构造: Constructor)命名空间 , 属性依然要设置set方法--
bean iduser classcom.ffyc.domain.User c:name张三/
bean的作用域
在Spring中那些组成应用程序的主体及由Spring IoC容器所管理的对象被称之为bean。简单地讲bean就是由IoC容器初始化、装配及管理的对象
Singleton
Singleton是单例类型就是在创建起容器时就同时自动创建了一个bean的对象不管你是否使用他都存在了每次获取到的对象都是同一个对象。
bean iduser classcom.ffyc.domain.User scopesingleton
Prototype
Prototype作用域的bean会导致在每次对该bean请求将其注入到另一个bean中或者以程序的方式调用容器的getBean()方法时都会创建一个新的bean实例。Prototype是原型类型它在我们创建容器的时候并没有实例化而是当我们获取bean的时候才会去创建一个对象而且我们每次获取到的对象都不是同一个对象。