Spring學習筆記(搭建)

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章