日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

【转】Spring 的下载、安装和使用

發(fā)布時(shí)間:2025/3/20 javascript 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【转】Spring 的下载、安装和使用 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、下載 Spring 下載地址:http://repo.spring.io/libs-release-local/org/springframework/spring/4.0.6.RELEASE/? ? 下載zip壓縮包: ?spring-framework-4.0.6.RELEASE-dist.zip 并解壓。

?

二、在 Eclipse 呀 myEclipse 中開發(fā) Spring 應(yīng)用

?

? 1. 新建 java project? 項(xiàng)目命名為 myspring

? 2. 為該項(xiàng)目增加 Spring 支持。添加用戶庫 spring4.0.6 和 common-logging 添加方法如下圖:


commons-logging-1.1.3.jar


? 3. 定義一個(gè) Spring 管理容器中的 Bean? (POJO)? src\hsl\service\PersonService.java 代碼如下:?

[java]?view plaincopy
  • package?hsl.service;??
  • ??
  • public?class?PersonService?{??
  • ????private?String?name;??
  • ??
  • ????//?name屬性的setter方法??
  • ????public?void?setName(String?name)?{??
  • ????????this.name?=?name;??
  • ????}??
  • ??
  • ????//?測試Person類的info方法??
  • ????public?void?info()?{??
  • ????????System.out.println("此人名為:"?+?name);??
  • ????}??
  • }??
  • 注:spring?可以管理任意的 POJO,并不要求?Java?類是一個(gè)標(biāo)準(zhǔn)的 JavaBean.

    ? 4.?編寫主程序,該程序初始化 Spring 容器 src\hsl\SpringTest.java? 代碼如下:

    [java]?view plaincopy
  • package?hsl;??
  • ??
  • import?hsl.service.PersonService;??
  • import?org.springframework.context.ApplicationContext;??
  • import?org.springframework.context.support.ClassPathXmlApplicationContext;??
  • ??
  • public?class?SpringTest?{??
  • ????public?static?void?main(String[]?args)?{??
  • ????????//?創(chuàng)建Spring的ApplicationContext??
  • ????????ApplicationContext?ctx?=?new?ClassPathXmlApplicationContext("bean.xml");??
  • ????????System.out.println(ctx);?//?輸出Spring容器??
  • ??
  • ????????//?通過?Spring?容器獲取?Person?實(shí)例,并為?Person?實(shí)例設(shè)置屬性值(這種方式稱為控制反轉(zhuǎn),IoC)??
  • ????????PersonService?p?=?ctx.getBean("personService",?PersonService.class);??
  • ????????p.info();??
  • ????}??
  • }??
  • ? 5. 將 PersionService 類部署在 Spring 配置文件中, src\bean.xml? 代碼如下:

    [html]?view plaincopy
  • <?xml?version="1.0"?encoding="UTF-8"?>??
  • <beans?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??
  • ????xmlns="http://www.springframework.org/schema/beans"??
  • ????xsi:schemaLocation="http://www.springframework.org/schema/beans??
  • ????http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">??
  • ????<!--?將PersonService類部署成Spring容器中的Bean??-->??
  • ????<bean?id="personService"?class="hsl.service.PersonService">??
  • ????????<property?name="name"?value="wawa"/>??
  • ????</bean>??
  • </beans>??
  • ? 6. 運(yùn)行主程序,結(jié)果如下:

    ?


    ?

    轉(zhuǎn)載于:https://www.cnblogs.com/printN/p/6419034.html

    總結(jié)

    以上是生活随笔為你收集整理的【转】Spring 的下载、安装和使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。