国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序完成


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 叶城县| 宣城市| 金沙县| 遂溪县| 绵竹市| 封开县| 池州市| 禹州市| 保靖县| 麦盖提县| 诸城市| 鹰潭市| 阜康市| 清原| 金秀| 宁乡县| 灵璧县| 肇东市| 宜昌市| 翁牛特旗| 张家川| 新沂市| 宁强县| 南皮县| 图们市| 长寿区| 个旧市| 措勤县| 营山县| 胶州市| 新昌县| 龙游县| 吴堡县| 安福县| 望谟县| 博野县| 饶阳县| 金堂县| 民和| 德钦县| 萝北县|