国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1、Spring初學入門教程

2019-11-08 03:09:08
字體:
來源:轉載
供稿:網友

1、SPRing初學入門教程

第一個HelloWorld程序

工程是在以下開發環境下完成的

Spring Framework 4.0.4 RELEASEEclipse MARS 版本maven plugin for eclipse

第一步:創建maven項目

這里寫圖片描述

第二步:創建目錄結構

這里寫圖片描述

第三步:添加代碼

beans.xml

<?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 id="HelloWorldImpl01" class="com.main.impl.HelloWorldImpl01"></bean> <bean id="HelloWorldImpl02" class="com.main.impl.HelloWorldImpl02"></bean> <bean id="helloWorldService" class="com.main.service.HelloWorldService"> <property name="helloWorld" ref="HelloWorldImpl02"/> </bean></beans>

HelloWorldService.java

package com.main.service;import com.main.model.HelloWorld;public class HelloWorldService { private HelloWorld helloWorld; //default constructor public HelloWorldService(){ } //HelloWHorld getter public HelloWorld getHelloWorld() { return helloWorld; } //HelloWorld setter public void setHelloWorld(HelloWorld helloWorld) { this.helloWorld = helloWorld; }}

HelloWorld.java

package com.main.model;public interface HelloWorld { public void sayHello();}

HelloWorldImpl01.java

package com.main.impl;import com.main.model.HelloWorld;public class HelloWorldImpl01 implements HelloWorld{ public void sayHello() { System.out.println("HelloWorldImpl-------01"); }}

HelloWorldImpl02.java

package com.main.impl;import com.main.model.HelloWorld;public class HelloWorldImpl02 implements HelloWorld{ public void sayHello() { System.out.println("HelloWorldImpl------02"); }}

APPTest.java

package com.main.SpringPart01;import org.junit.Test;import org.springframework.context.applicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.main.model.HelloWorld;import com.main.service.HelloWorldService;public class AppTest { @Test public void test(){ ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); HelloWorldService service =(HelloWorldService)context.getBean("helloWorldService"); HelloWorld hw= service.getHelloWorld(); hw.sayHello(); }}

第四步:測試運行結果

在以上代碼均添加完成后,運用AppTest的junit單元測試運行,可以看到控制臺輸出結果為下圖所示 這里寫圖片描述

到此,Spring的入門第一個helloworld程序完成


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永靖县| 阜城县| 武城县| 濮阳市| 左贡县| 乌审旗| 东光县| 北宁市| 衡山县| 庆城县| 分宜县| 桂东县| 巴彦淖尔市| 清流县| 航空| 什邡市| 宁远县| 上林县| 绍兴市| 崇义县| 波密县| 马关县| 灵武市| 新建县| 伊宁县| 瓦房店市| 文化| 喀喇| 平泉县| 宣恩县| 丹棱县| 乐昌市| 西充县| 阿克苏市| 将乐县| 尼木县| 教育| 陇西县| 屏边| 佛教| 文昌市|