第一步:加入jar包
第二步:创建配置文件
-申明javabean 配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="hw" class="com.amaker.test.HelloWorld">
<property name="name" value="amaker"/>
</bean>
</beans>
第三步:获取bean工厂
Resource r = new ClassPathResource("applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(r);
第四步:获取对象 HelloWorld h =(HelloWorld) factory.getBean("hw");