bean实例化--工厂方法
1,编写bean 1 package com.songyan.demo1; 2 3 /** 4 * 要创建的对象类 5 * @author sy 6 * 7 */ 8 public class User { 9 private String name; 10 private int age ; 11 public String getName() { 12 return name; 13 } 14 public void setName(String name) { 15 this.name = name; 16 } 17 public int getAge() { 18 return age; 19 } 20 public void setAge(int age) { 21 this.age = age; 22 } 23 24 } 2,编写工厂 1 package com.songyan.factory; 2 3 import com.songyan.demo1.User; 4 5 /** 6 * @author sy 7 * 工厂类 8 */ 9 public class Factory { 10 11 /** 12 * 非静态方法创建对象 13 * @return 14 */ 15 public User create() 16 { 17 return new User();