基于xml形式Bean注入
基于Annotation形式Bean注入
//基于纯注解完成数据注入
@Test
public void test(){
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(PersonBeanConfig.class);
PersonBean personBean = applicationContext.getBean(PersonBean.class);//类型
System.out.println(personBean.getAddress());
PersonBean person = (PersonBean)applicationContext.getBean("person");//属性名
System.out.println(person.getAddress());
String[] names= applicationContext.getBeanNamesForType(PersonBean.class);//查看在容器中当前Bean的属性名
for(String name:names){
System.out.println(name);
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.