Spring IOC实验

实验1:通过IOC容器创建对象,并为属性赋值★

HelloWorld 实现

实验2:根据bean的类型从IOC容器中获取bean的实例★

如果IOC容器这个类型的bean有多个,查找会报错
报错org.springframework.beans.factory.NoUniqueBeanDefinitionException

1
2
3
4
5
6
      /*Person bean = ioc.getBean(Person.class);
System.out.println(bean);
*/
// 指定类之后不需要强转
Person bean = ioc.getBean("person02", Person.class);
System.out.println(bean);
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×