1.工具
Eclipse+JDK8+Tomcat;
2.依赖包
Jar:commons-logging-1.1.1.jar+spring-core-4.0.5.RELEASE.jar
3.配置文件
xml:建立一个配置文件
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="myStudent" class="com.zxj.spring.entity.Student">
<property name="age">
<value>14</value>
</property>
<property name="name">
<value>spring!</value>
</property>
</bean>
</beans>
4:代码实现
<pre name="code" class="java">public class Student {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void show(){
System.out.println(name+"___"+age);
}
}
public class MainSpring {
public static void main(String[] args) {
ApplicationContext act = new FileSystemXmlApplicationContext("src/applicationContext.xml");
Student stu = (Student) act.getBean("myStudent");
stu.show();
}
}
Console输出:spring!___14