一、介绍
二、BeanFactory类图
三、示例
1 public class MainStarter { 2 3 public static void main(String[] args) { 4 5 // 注解配置引用上下文 6 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig.class); 7 8 // 1、简单获取bean 9 Person person = (Person) context.getBean("person"); 10 System.out.println("person:" + person); 11 12 context.close(); 13 } 14 } 15 16 @Configuration 17 public class MainConfig { 18 19 @Bean 20 public Person person() { 21 Person person = new Person(); 22 person.setName("张三"); 23 person.setSex("男"); 24 return person; 25 } 26 27 } 28 29 30 31 public class Person { 32 33 private String name; 34 35 private String sex; 36 37 public String getName() { 38 return name; 39 } 40 41 public void setName(String name) { 42 this.name = name; 43 } 44 45 public String getSex() { 46 return sex; 47 } 48 49 public void setSex(String sex) { 50 this.sex = sex; 51 } 52 53 @Override 54 public String toString() { 55 return "Person{" + 56 "name='" + name + '\'' + 57 ", sex='" + sex + '\'' + 58 '}'; 59 } 60 }
四、实现原理图
五、IOC原理图