一、【项目架构】
比较简单,一个实体类(User)、一个测试类
二、【配置文件】
schema的路径:D:\springFrammework\spring-framework-3.2.0.RELEASE\docs\spring-framework-reference\htmlsingle\index.html
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="com.sinomach.pojo.User" id="user">
<property name="name" value="公孙离"/>
<property name="age" value="22"/>
</bean>
</beans>
三、【程序测试】
package com.sinomach.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.sinomach.pojo.User;
public class Test {
public static void main(String[] args){
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
User user = ac.getBean("user",User.class);
System.out.println(user);
}
}
运行结果: