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

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

spring學習之helloworld

2019-11-14 15:03:16
字體:
來源:轉載
供稿:網友

準備學習sPRing,每天下班學一點

環境準備

eclipse mar 4.5.1:下載地址

Spring STS 4.5.1插件: 下載地址(可以去http://spring.io/tools/sts/all下載最新版本)

maven 3.3.9(由于我準備使用maven創建spring依賴):下載地址

一.maven 相關基礎知識 和環境修改

a.添加環境變量 M2_HOME=C:/java/apache-maven-3.3.3

path中追加 %M2_HOME%/bin;

mvn 常用指令:http://www.survivalescaperooms.com/holly/archive/2013/06/15/3137041.html

修改mvn中央庫為oschina: http://maven.oschina.net/help.html

修改eclipse中mvn設置

 

2.創建基于mvn的spring 工程

a.打開eclipse 新建maven 工程

  b.編輯pom.xml文件

  打開spring 官網http://projects.spring.io/spring-framework/,找到相關配置,添加到pom.xml中,等待eclipse從oschina下載對應jar和source-jar

     

下載完成結果

至此,基于maven的spring環境搭建完成

 3.創建spring之HelloWord

    a.介紹工程結構

    HelloWord 類:為即將聲明的bean

        Main類:為測試方法

            applicationContext.xml:spring bean 定義文件

   b.編寫相關代碼

   HelloWord

public class HelloWord{    private String name;    public String getName()    {        return name;    }    public void setName(String name)    {        this.name = name;    }        public void sayHello()    {        System.out.println("hello:"+name);    }}

  Application.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="baseModel" class="com.liangpeng.spring.beans.HelloWord">		<property name="name" value="Spring"></property>	</bean></beans>

  Main

public class Main{    public static void main(String[] args)    {        @SuppressWarnings ("resource")        ApplicationContext ioc =new ClassPathXmlApplicationContext("ApplicationContext.xml");                HelloWord hello =ioc.getBean(HelloWord.class);                hello.sayHello();            }}

  運行Main,會發現spring通過反射在ioc容器中實例化HelloWord,并將hello的name設置為Spring

十一月 18, 2015 8:31:06 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@6193b845: startup date [Wed Nov 18 20:31:06 CST 2015]; root of context hierarchy十一月 18, 2015 8:31:06 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions信息: Loading XML bean definitions from class path resource [ApplicationContext.xml]hello:Spring

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鹤壁市| 泰顺县| 伊春市| 英山县| 岳普湖县| 柳州市| 凤台县| 资中县| 安远县| 开江县| 中卫市| 大化| 晋中市| 册亨县| 隆昌县| 德安县| 桃园县| 平昌县| 密云县| 隆子县| 石台县| 永济市| 建阳市| 六枝特区| 满洲里市| 吴堡县| 视频| 金寨县| 鄂伦春自治旗| 安溪县| 沁阳市| 葫芦岛市| 泰顺县| 南丰县| 平山县| 腾冲县| 丁青县| 通榆县| 信丰县| 泰安市| 西安市|