การวิจัยหลักในบทความนี้คือรหัสอินสแตนซ์ของ Hello Spring สำหรับการสร้างโครงการในการเรียนรู้ฤดูใบไม้ผลิดังนี้
1. Eclipse สร้าง Java Project HelloSpring
2. สร้างไดเรกทอรี LIB และเพิ่มแพ็คเกจ 5 ขวดที่จำเป็นสำหรับฤดูใบไม้ผลิ
3. เลือก 5 ไฟล์คลิกขวา -> Build Path -> เพิ่มไปยัง Build Path
1. สร้างแพ็คเกจ io.spring.beans และเขียน helloWorld.java
แพ็คเกจ io.spring.beans;/** * @author Alex อีเมล: [email protected] * @version 1.0 */คลาสสาธารณะ HelloWorld {ชื่อสตริงส่วนตัว; โมฆะสาธารณะ setName (ชื่อสตริง) {this.name = name;
2. คลิกขวาที่ src-> สร้าง file Spring Bean Configuration File ApplicationContext.xml
<? xml version = "1.0" การเข้ารหัส = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://ww.w3.org/2001/xml XSI: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <! </ebean> </ebeans>
3. เขียน main.java
แพ็คเกจ io.spring.beans; นำเข้า org.springframework.context.applicationContext; นำเข้า org.springframework.context.support.classpathxmlapplicationContext;/** * @author Pangpang args) {// 1 สร้าง Spring IOC Container Object ApplicationContext CTX = ใหม่ classPathxMlApplicationContext ("ApplicationContext.xml"); // 2 รับอินสแตนซ์ถั่วจาก IOC คอนเทนเนอร์ HelloWorld HelloWorld = (HelloWorld) CTX.GetBean ("HelloWorld"); // 3 โทรหา Hello Method HelloWorld.hello ();}} ผลลัพธ์ผลลัพธ์
เมื่อบันทึกสปริงสีแดงอยู่ในคอนโซลหมายความว่าแอปพลิเคชันฤดูใบไม้ผลิสำเร็จ
ข้างต้นเป็นเนื้อหาทั้งหมดของบทความนี้เกี่ยวกับรหัสอินสแตนซ์ของ Hello Spring สำหรับการสร้างโครงการในการเรียนรู้ฤดูใบไม้ผลิ ฉันหวังว่ามันจะเป็นประโยชน์กับทุกคน เพื่อนที่สนใจสามารถอ้างถึงหัวข้ออื่น ๆ ที่เกี่ยวข้องในเว็บไซต์นี้ต่อไป หากมีข้อบกพร่องใด ๆ โปรดฝากข้อความไว้เพื่อชี้ให้เห็น ขอบคุณเพื่อนที่ให้การสนับสนุนเว็บไซต์นี้!