Myeclipse2017 สร้างโครงการฤดูใบไม้ผลิสำหรับการอ้างอิงของคุณ เนื้อหาเฉพาะมีดังนี้
1. สร้างโครงการเว็บ
2. คลิกขวาในโครงการ-> คุณสมบัติ
3. ค้นหาสปริง -> peoject facets -> ค้นหาฤดูใบไม้ผลิทางด้านขวาตรวจสอบและบันทึก
4. ทดสอบ
4.1 สร้างคลาส
แพ็คเกจ cn.spring.user;/**** @author dzsom* @date 13 มีนาคม 2018 เวลา 23:42:03 PM* @encoding UTF-8* @version 1.0 **/ผู้ใช้คลาสสาธารณะ {uname สตริงส่วนตัว; อายุ int ส่วนตัว; สตริงสาธารณะ getUname () {return uname; } โมฆะสาธารณะ setUname (uname string) {this.uname = uname; } public int getage () {return Age; } การตั้งค่าโมฆะสาธารณะ (อายุ int) {this.age = อายุ; -4.2 แก้ไขไฟล์กำหนดค่า ApplicationContext.xml ภายใต้ SRC
<? xml version = "1.0" การเข้ารหัส = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://ww.w3.org/2001/xml xmlns: p = "http://www.springframework.org/schema/p" xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd "> <!-ปล่อยให้วัตถุไปสู่การจัดการฤดูใบไม้ผลิ-> <Bean name =" ผู้ใช้ "> </epean> </epeans>
4.3 สร้างคลาสทดสอบ (@Test ต้องนำเข้าแพ็คเกจ Junit)
แพ็คเกจ cn.spring.test; นำเข้า org.junit.test; นำเข้า org.springframework.context.applicationContext; นำเข้า org.springframework.context.support.classpathxmlapplicationcontext; @encoding UTF-8*@Version 1.0 **/การสาธิตคลาสสาธารณะ {@Test Public Void Fun () {// 1 สร้างออบเจ็กต์คอนเทนเนอร์ ApplicationContext AC = ใหม่ classPathxMlApplicationContext ("ApplicationContext.xml"); // 2. ถามคอนเทนเนอร์สำหรับผู้ใช้วัตถุผู้ใช้ = (ผู้ใช้) ac.getBean ("ผู้ใช้"); // 3. พิมพ์ System.out.println (ผู้ใช้); -4.4 คลิกขวาเพื่อเรียกใช้การทดสอบ หากมีเอาต์พุตค่าสปริงจะถูกสร้างขึ้นสำเร็จ
ข้างต้นเป็นเนื้อหาทั้งหมดของบทความนี้ ฉันหวังว่ามันจะเป็นประโยชน์ต่อการเรียนรู้ของทุกคนและฉันหวังว่าทุกคนจะสนับสนุน wulin.com มากขึ้น