隨筆 - 1  文章 - 37  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          留言簿(16)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          test

          搜索

          •  

          最新評(píng)論

          關(guān)于本文
          本文記錄了將Spring Web Application應(yīng)用到OSGI環(huán)境中,也就是OSGI Web應(yīng)用。
          [請(qǐng)點(diǎn)擊這里下載本文的Eclipse工程]
          org.phrancol.osgi.demo.launcher工程中啟動(dòng)應(yīng)用。

          一、準(zhǔn)備工作

          1,JDK 1.5
          2,Eclipse 3.3-jee (MyEclipse)
          3,Spring-framework-2.1-m3
          4,Spring-osgi-1.0-m2

          二、搭建環(huán)境

          1,首先當(dāng)然需要一個(gè)Http Server,那就用Eclipse自帶的Jetty吧。
          2,將Jetty和它的依賴包作為 Plugin 工程導(dǎo)入Eclipse,  Import -> Plug-ins and fragments -> Next

           3,創(chuàng)建一個(gè)普通工程做為Eclipse Launch的存放目錄 org.phrancol.osgi.demo.launcher
           4,Open Run Dialog ... -> OSGI Framework -> New Configuration ,名字改為org.phrancol.osgi.demo.web.launcher,在
          Common面板Save as 里面的 Shared file指定目錄到 org.phrancol.osgi.demo.launcher

          5,Apply,  Run ,可以看到一個(gè)Launch已經(jīng)生成,通過Console可以看到Jetty也成功啟動(dòng)
          6,在OSGI輸入exit退出,(注:如果不退出,那么它將駐留內(nèi)存,大概會(huì)消耗20K的內(nèi)存)

          三、Equinox/Spring-osgi環(huán)境

          導(dǎo)入Spring-osgi和它的依賴包(注:導(dǎo)入Spring包的時(shí)候,plug-in Location 要指定Spring-osgi的lib目錄),導(dǎo)入完畢后,形成的project結(jié)構(gòu)如下圖


          四、jpetstore
          使用Spring自帶的jpetstore,代碼和配置文件都是現(xiàn)成的,能省去一些不必要的開發(fā)。

          五、首頁
          jpetstore默認(rèn)是springmvc,向HttpService注冊(cè)Servlet或是Resource,jpetstore里面需要注冊(cè)的servlet就是ContextLoaderServlet和DispatcherServlet,resource則是view層的jsp等。
          1,創(chuàng)建個(gè)plug-in project ,OSGI Framework選擇Equinox,創(chuàng)建Activator,org.phrancol.osgi.jpetstore.springmvc
          2,創(chuàng)建一個(gè)web目錄,這個(gè)目錄就是web應(yīng)用的目錄,將jpetstore里面的WEB-INF/jsp目錄拷貝進(jìn)去
          3,在 META-INF 目錄中創(chuàng)建 dispatcher 目錄,將petstore-servlet.xml拷貝進(jìn)去,修改成如下代碼
          <?xml version="1.0" encoding="UTF-8" ?>
          <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

          <!--
            - DispatcherServlet application context for the Spring web MVC
            - implementation of JPetStore's web tier.
            
          -->
          <beans>

              
          <!-- ========================= VIEW DEFINITIONS ========================= -->

              
          <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                  
          <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
                  
          <property name="prefix" value="/web/jsp/spring/"/>
                  
          <property name="suffix" value=".jsp"/>
              
          </bean>

              
          <!-- ========================= DEFINITIONS OF PUBLIC CONTROLLERS ========================= -->

              
          <bean id="defaultHandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>

              
          <bean name="/shop/index.do" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
                  
          <property name="viewName" value="index"/>
              
          </bean>

          </beans>

          4,在Activator的start(BundleContext context)里面注冊(cè)servlet和resource,代碼如下
          public void start(BundleContext context) throws Exception {
                  ServiceReference sr 
          = context.getServiceReference(HttpService.class
                          .getName());
                  HttpService httpService 
          = (HttpService) context.getService(sr);
                  httpService.registerResources(
          "/""/web"null);
                  httpService.registerServlet(
          "/*.jsp"new JspServlet(context
                          .getBundle(), 
          "/web/jsp"), nullnull);
                  Dictionary
          <String, String> initparams = new Hashtable<String, String>();
                  initparams.put(
          "load-on-startup""1");
                  DispatcherServlet dispatcherServlet 
          = new DispatcherServlet();
                  dispatcherServlet
                          .setContextConfigLocation(
          "META-INF/dispatcher/petstore-servlet.xml");

                  initparams 
          = new Hashtable<String, String>();
                  initparams.put(
          "servlet-name""petstore");
                  initparams.put(
          "load-on-startup""2");
                  httpService.registerServlet(
          "/*.do", dispatcherServlet, initparams,
                          
          null);

              }

          注意依賴包關(guān)系
          啟動(dòng)后,在訪問http://localhost/shop/index.do頁面,報(bào)錯(cuò),看來要解決一下標(biāo)簽庫問題,在web目錄中建立一個(gè)WEB-INF目錄,將c.tld, fmt.tld拷貝進(jìn)去,然后在osgi控制臺(tái)refresh springmvc,再訪問這個(gè)頁面,發(fā)現(xiàn)沒有圖片,把jpetstore/images目錄拷貝到web目錄下,再refresh一下,OK,首頁出來了。

          六、結(jié)束語
           這部分簡(jiǎn)單記錄了如何使用springmvc,下部分將記錄如何將jpetstore的各個(gè)層通過spring-osgi應(yīng)用起來

          posted on 2007-09-06 14:09 Phrancol Yang 閱讀(6299) 評(píng)論(9)  編輯  收藏 所屬分類: OSGI

          FeedBack:
          # re: Developing Equinox/Spring-osgi/Spring Framework Web Application Part 1 - 顯示首頁 2007-09-08 12:45 Friszart
          寫得很清晰!  回復(fù)  更多評(píng)論
            
          # re: Developing Equinox/Spring-osgi/Spring Framework Web Application Part 1 - 顯示首頁 2007-10-31 10:25 fangzx
          謝謝作者,寫的非常清楚,條理分明。準(zhǔn)備照做一下。

          下載本文的Eclipse工程: 下載不了!  回復(fù)  更多評(píng)論
            
          # re: Developing Equinox/Spring-osgi/Spring Framework Web Application Part 1 - 顯示首頁 2007-10-31 21:31 Phrancol Yang
          可以下載啊,我剛剛才試的,這個(gè)blog提供的空間太小,所以就放到免費(fèi)的網(wǎng)絡(luò)硬盤上了,可能有些不穩(wěn)定,多試一下  回復(fù)  更多評(píng)論
            
          # re: Developing Equinox/Spring-osgi/Spring Framework Web Application Part 1 - 顯示首頁 2007-10-31 21:40 Fangzx
          Phrancol Yang,謝謝回復(fù)。不過,還是無法下載。

          1、我發(fā)現(xiàn)了類似的Blog文章:
          http://thegoodthebadtheugly.wordpress.com/2007/05/20/springosgi/7
          希望本文作者能多提供技術(shù)支持,整個(gè)過程問題太多了,比較痛苦。

          2、我按照本文步驟做了一下,不過我用的是 :
          spring-framework-2.5-rc1
          spring-osgi-1.0-m3
          最后遇到問題,找不到下面的插件:
          javax.servlet.jsp.jstl.fmt
          org.apache.taglibs.standard.tag.common.fmt
          不知道到哪里下載?

          3、發(fā)現(xiàn) spring-osgi-1.0-m3中好像少了很多插件,所以只能重新下載spring-osgi-1.0-m2,從其中提取了很多插件。

          4、我的ss內(nèi)容:

          id State Bundle
          0 ACTIVE org.eclipse.osgi_3.3.1.R33x_v20070828
          1 INSTALLED org.springframework.bundle.spring.webmvc_2.5.0.rc1
          2 ACTIVE org.springframework.osgi.spring-osgi-extender_1.0.0.m3
          3 ACTIVE org.mortbay.jetty_5.1.11.v200706111724
          4 ACTIVE org.eclipse.osgi.services_3.1.200.v20070605
          5 ACTIVE org.eclipse.equinox.http.servlet_1.0.1.R33x_v20070816
          6 ACTIVE org.eclipse.equinox.http.jetty_1.0.1.R33x_v20070816
          7 INSTALLED org.springframework.osgi.jstl.osgi_1.1.2.SNAPSHOT
          8 ACTIVE org.apache.commons.logging_1.0.4.v200706111724
          9 ACTIVE org.springframework.osgi.spring-osgi-io_1.0.0.m3
          10 ACTIVE javax.servlet.jsp_2.0.0.v200706191603
          11 ACTIVE javax.servlet_2.4.0.v200706111738
          12 ACTIVE org.eclipse.equinox.jsp.jasper_1.0.1.R33x_v20070816
          13 ACTIVE org.springframework.osgi.aopalliance.osgi_1.0.0.SNAPSHOT
          14 ACTIVE org.springframework.bundle.spring.core_2.5.0.rc1
          15 ACTIVE org.springframework.bundle.spring.context_2.5.0.rc1
          16 ACTIVE org.springframework.osgi.spring-osgi-core_1.0.0.m3
          17 ACTIVE org.springframework.osgi.cglib-nodep.osgi_2.1.3.SNAPSHOT
          18 ACTIVE org.springframework.bundle.spring.web_2.5.0.rc1
          19 ACTIVE org.springframework.bundle.spring.beans_2.5.0.rc1
          20 ACTIVE org.springframework.bundle.spring.aop_2.5.0.rc1
          21 ACTIVE org.apache.commons.el_1.0.0.v200706111724
          22 INSTALLED org.phrancol.osgi.jpetstore.springmvc_1.0.0
          23 ACTIVE org.apache.jasper_5.5.17.v200706111724

            回復(fù)  更多評(píng)論
            
          # re: Developing Equinox/Spring-osgi/Spring Framework Web Application Part 1 - 顯示首頁 2007-10-31 22:53 Fangzx
          @Phrancol Yang
          非常感謝你的回復(fù)。用IE可以下載了(原來用FF)。
          我會(huì)加你的QQ,期望得到你的更多的指教。  回復(fù)  更多評(píng)論
            
          # re: Developing Equinox/Spring-osgi/Spring Framework Web Application Part 1 - 顯示首頁 2007-11-19 10:58 gembin
          請(qǐng)點(diǎn)擊這里下載本文的Eclipse工程]

          無法下載+!

          如何下載?

          Gembin@gmail.com  回復(fù)  更多評(píng)論
            
          # re: Developing Equinox/Spring-osgi/Spring Framework Web Application Part 1 - 顯示首頁 2007-11-19 15:50 Phrancol
          免費(fèi)網(wǎng)絡(luò)硬盤,你在“立即提取文件”欄目中點(diǎn)一下‘提取’,會(huì)進(jìn)入下載頁面  回復(fù)  更多評(píng)論
            
          # re: Developing Equinox/Spring-osgi/Spring Framework Web Application Part 1 - 顯示首頁 2008-02-13 10:23 delphixp
          @Phrancol

          點(diǎn)擊"提取" 按鈕, 沒任何反應(yīng)....  回復(fù)  更多評(píng)論
            
          # re: Developing Equinox/Spring-osgi/Spring Framework Web Application Part 1 - 顯示首頁 2008-02-14 16:25 Phrancol Yang
          用IE瀏覽器  回復(fù)  更多評(píng)論
            
          主站蜘蛛池模板: 新余市| 鄢陵县| 凤山县| 金平| 贵阳市| 台东县| 南康市| 永春县| 中江县| 汉阴县| 乐昌市| 鄂温| 淳化县| 耿马| 新营市| 吉林市| 桦南县| 诸暨市| 屏南县| 文水县| 米易县| 永福县| 太原市| 出国| 项城市| 新巴尔虎右旗| 新源县| 渑池县| 阿瓦提县| 汉川市| 东乌| 林甸县| 华安县| 海淀区| 温州市| 新田县| 濮阳市| 凤凰县| 武穴市| 泰安市| 柳江县|