Spring写第一个hello world程序
先new->spring Bean Configuration ->创建.xml文件
<bean id="person" class="comt.atguigu.person.Student"> //bean标签是类,id用于做区别
<property name="name" value="tony"> //property是给属性赋值
</property>
</bean>
//创建spring ioc容器对象,ClassPathXmlApplicationContext(为xml配置文件)
ApplicationContext cxt =new ClassPathXmlApplicationContext("springbeancontext.xml");
//获取person对象,默认为Obj类型
Student student = (Student)cxt.getBean("person"); //括号里传id
student.sayHello();
网友评论