<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    J2EE之巔

     

    基于Spring DM的WEB應用開發

     

    Spring DM 1.1.x的最大特性便是它可以支持在其中部署WEB應用,我使用后感覺這是個很酷的特性,我甚至覺得用這種方式開發基于OSGi WEB應用比使用Spring DM Server更好,至少目前你可以獲得更好的便攜性(可以在多個Spring DM支持的OSGi平臺上運行),并且Spring DM Server并沒有提供更多的企業應用支持。

    不過對于剛使用Spring DM進行WEB應用開發的人來說,成功地配置卻不是一件容易的事。以下詳細的講解一下相關配置。

    1  運行環境所需的Bundles

    0             ACTIVE      system.bundle_3.2.2.R32x_v20070118

    1             ACTIVE      com.springsource.slf4j.api_1.5.0

    2             RESOLVED    org.springframework.osgi.jetty.web.extender.fragment.osgi_1.0.0

                               Master=46

    3             ACTIVE      org.springframework.bundle.osgi.extender_1.0.1.v200803070100

    4             ACTIVE      org.springframework.bundle.spring.core_2.5.5

    5             ACTIVE      org.springframework.bundle.spring.web_2.5.5

    6             ACTIVE      com.springsource.org.objectweb.asm_2.2.3

    7             RESOLVED    osgi_log_config_1.0.0

                               Master=36

    8             ACTIVE      org.springframework.bundle.osgi.core_1.0.1.v200803070100

    9             ACTIVE      com.springsource.slf4j.log4j_1.5.0

    10           ACTIVE      org.springframework.bundle.spring_2.5.2.v200803070100

    11           ACTIVE      org.springframework.bundle.spring.context_2.5.5

    12           ACTIVE      javax.servlet_2.4.0.v200706111738

    13           ACTIVE      org.springframework.osgi.servlet-api.osgi_2.5.0.SNAPSHOT

    14           ACTIVE      com.springsource.net.sf.cglib_2.1.3

    15           ACTIVE      org.springframework.bundle.spring.beans_2.5.5

    16           ACTIVE      javax.servlet.jsp_2.0.0.v200706191603

    18           ACTIVE      org.springframework.osgi.jetty.start.osgi_1.0.0

    19           ACTIVE      org.springframework.bundle.osgi.io_1.0.1.v200803070100

    20           ACTIVE      org.aopalliance_1.0.0

    21           ACTIVE      org.springframework.bundle.spring.context.support_2.5.5

    23           ACTIVE      com.springsource.org.aopalliance_1.0.0

    24           ACTIVE      org.springframework.bundle.spring.aop_2.5.5

    25           ACTIVE      com.springsource.slf4j.org.apache.commons.logging_1.5.0

    30           ACTIVE     org.objectweb.asm_2.2.3

    33           ACTIVE      org.mortbay.jetty.server_6.1.9

    35           ACTIVE      org.mortbay.jetty.util_6.1.9

    36           ACTIVE      org.springframework.osgi.log4j.osgi_1.2.15.SNAPSHOT

                               Fragments=7

    37           ACTIVE      org.mortbay.jetty_5.1.11.v200706111724

    43           ACTIVE      org.springframework.bundle.osgi.extender_1.1.2

    44           ACTIVE      org.springframework.bundle.osgi.io_1.1.2

    45           ACTIVE      org.springframework.bundle.osgi.web_1.1.2

    46           ACTIVE      org.springframework.bundle.osgi.web.extender_1.1.2

                               Fragments=2

    47           ACTIVE      org.springframework.bundle.osgi.core_1.1.2

    以上這些Bundles可以在spring dm 1.1.2的發布包中找到,以上Bundlesstart level設置為2

    2 加入Log4j日志配置Bundles

    這個Bundles的目的在于提供log4j.properties,詳細做法可以參考本人的”spring osgi快速入門

    3 開發WEB應用

    WEB應用的開發方式和普通的WEB基本上一樣,只是加入一些OSGi的配置。

    大致結構如下:

    META-INF

                   MANIFEST.MF

    WEB-INF

                   Classes

                   Lib

                   Web.xml

                   applicationContext.xml

    1 MANIFEST.MF配置參考:

    Manifest-Version: 1.0

    Bundle-ManifestVersion: 2

    Bundle-Name: Osgi_web_app Plug-in

    Bundle-SymbolicName: osgi_web_app

    Bundle-Version: 1.0.0

    Bundle-Vendor: ccsoft

    Import-Package: javax.servlet,

     javax.servlet.http,

     javax.servlet.resources;version="2.4.0",

     org.ccsoft.service,

     org.springframework.osgi.web.context.support;version="1.1.2",

     org.springframework.web.context,

     org.springframework.web.context.support

    Bundle-ClassPath: WEB-INF/classes/,

     .

    Require-Bundle: org.springframework.bundle.osgi.core,

     org.springframework.bundle.osgi.io,

     org.springframework.bundle.spring.beans,

     org.springframework.bundle.spring.context,

     org.springframework.bundle.spring.core

    2 為了在web應用中使用spring dmIoC功能,web.xml中需要加入一些特定配置,類似于使用Spring時的配置,web.xml配置參考如下:

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

          version="2.4">

          <display-name>Simple Osgi WebApp Bundle</display-name>

          <description>Simple OSGi War</description>

          <context-param>

           <param-name>contextClass</param-name>                                                                        

           <param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>   

          </context-param>

         

          <listener>

           <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>                       

          </listener>

          <servlet>

                <servlet-name>MyServlet</servlet-name>

                <servlet-class>org.ccsoft.web.MyServlet</servlet-class>

          </servlet>

         

          <servlet-mapping>

                <servlet-name>MyServlet</servlet-name>

                <url-pattern>/servlet</url-pattern>

          </servlet-mapping>

         

         

    </web-app>

    至于applicationContext.xml則是標準的spring dm配置文件形式,只是沒有放在我們所熟悉的位置(META-INF/spring

    配置示例:

    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"

     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

     xmlns:osgi="http://www.springframework.org/schema/osgi"

     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

                                   http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">

         

          <osgi:reference id="HelloServiceOsgi" interface="org.ccsoft.service.SpeakService"/>

    </beans>

    在你的WEB應用中可以使用如下代碼來訪問別的Bundle提供的服務

    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(req.getSession().getServletContext());

    SpeakService ss=(SpeakService)ctx.getBean("HelloServiceOsgi");

    與你使用Spring開發WEB應用的寫法是完全一致的。

    好了現在你可以利用spring dm開發你的web應用了。更多相關問題還會在后續文章中逐一討論。

    蔡超

    軟件架構師

    Chao.cai@hp.com

    Chaocai2001@yahoo.com.cn

    致力于OSGi在中國的推廣

    posted on 2008-12-22 17:20 超越巔峰 閱讀(3171) 評論(1)  編輯  收藏

    評論

    # re: 基于Spring DM的WEB應用開發[未登錄] 2010-07-15 11:16 Jack

    我現在也在做spring-dm和war包相關的部署,我看了一下配置和你這個差不多,但是一運行就會出現OsgiBundleXmlWebApplicationContext這個類NoClassDefFoundError這樣的錯誤,請問你有沒有遇到過這個問題呢?  回復  更多評論   


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产亚洲人成网站在线观看| 日韩一级在线播放免费观看| 亚洲精品无码成人AAA片| EEUSS影院WWW在线观看免费| 亚洲国产精品无码久久青草| 成人嫩草影院免费观看| 亚洲成片观看四虎永久| 久久久久久国产a免费观看不卡 | 亚洲国产精品自在拍在线播放| 色五月五月丁香亚洲综合网| 免费日本黄色网址| 永久免费观看黄网站| 久久国产亚洲精品麻豆| 亚洲AV日韩AV天堂一区二区三区| 人妻在线日韩免费视频| 亚洲一级二级三级不卡| 波多野结衣中文字幕免费视频| 亚洲成a人片在线不卡| 99re8这里有精品热视频免费| 亚洲女久久久噜噜噜熟女 | 亚洲AV无码一区二区大桥未久| 国产网站在线免费观看| 日韩在线观看视频免费| 久久亚洲精品中文字幕无码| 久久精品国产免费观看 | 2020久久精品亚洲热综合一本| 麻豆成人精品国产免费| 一个人免费播放在线视频看片| 成年免费大片黄在线观看岛国| 久久99国产亚洲精品观看| 亚洲免费网站在线观看| 亚洲av无码专区首页| 亚洲一级片免费看| 中文字幕天天躁日日躁狠狠躁免费| 亚洲日本乱码卡2卡3卡新区| 亚洲国产成人五月综合网 | 黑人大战亚洲人精品一区 | 一级白嫩美女毛片免费| 亚洲视频一区在线| 无码欧精品亚洲日韩一区夜夜嗨 | 久久精品国产亚洲AV麻豆网站 |