创建对象的三种方式分别为构造函数创建、实例工厂构建和静态工厂构建
1 构造函数创建
无参构造函数创建 :默认
有参构造函数创建:要配置
有参构造函数创建例子(无参构造此处不做描述)
people.class测试对象
import lombok.Data;
// @data是lombok.Data的注解可以自动生成setter和getter
@Data
public class People {
private int id;
private String name;
/*public People() {
super();
System.out.println("执行无参构造函数");
}*/
public People(int id, String name) {
super();
this.id = id;
this.name = name;
System.out.println("执行有参构造函数");
}
@Override
public String toString() {
return "People{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
applicationContext.xml配置文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema