public class Person {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Configuration
public class AppConfig {
@Bean
public Person person() {
return new Person();
}
}
新建一个测试用例
/**
* AnnotationConfigApplicationContext入口,测试spring-IOC源码执行流程
*/
public class AnnotationConfigApplicationContextEntry {
@Test
public void entry() {
// Create the container
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
// retrieve the bean of Person class
Object bean = context.getBean("person");
//close the container
context.close();
}
}