隨筆-7  評論-3  文章-0  trackbacks-0
          轉(zhuǎn)載請注明出處 http://www.aygfsteel.com/fireflyk/archive/2011/09/18/358922.html

          網(wǎng)上找了很多例子,看了很多資料發(fā)現(xiàn)都不能完全重現(xiàn)一個(gè)OSGi的Web Demo
          本文結(jié)合了《OSGi原理與最佳實(shí)踐》+公司同事的《OSGi開發(fā)》+自己的理解。

          環(huán)境WindowXP + eclipse3.4 + Spring OSGi1.2.1
          1. 創(chuàng)建timeservice Bundle,提供輸出時(shí)間的功能
          1.1 eclipse內(nèi)創(chuàng)建Maven Project,選quickstart project:timeservice,package org.osgichina.demo.timeservice
          1.2 創(chuàng)建好后,remove maven的jar包,刪掉project中的App和AppTest,在項(xiàng)目上右鍵->PDE Tools->Convert
          1.3
          package org.osgichina.demo.timeservice;

          public interface TimeService {
              String getCurrentTime();
          }

          public class TimeServiceImpl implements TimeService {

              
          public String getCurrentTime() {
                  
          return (new Date()).toString();
              }

          }

          1.4 Spring配置
          配置放在META-INF/spring目錄下,框架啟動時(shí)會按照這個(gè)路徑去尋找配置文件
          timeservice.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">

              
          <!-- timeService bean -->
              
          <bean name="timeService" class="org.osgichina.demo.timeservice.impl.TimeServiceImpl" />

          </beans>

          timeservice-osgi.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" 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"
          >

              
          <!-- 將timeService 這個(gè)bean發(fā)布為OSGi服務(wù)的定義-->
              
          <osgi:service id="osgiTimeService" ref="timeService" interface="org.osgichina.demo.timeservice.TimeService">
              
          </osgi:service>

          </beans>

          這個(gè)Bundle到此已經(jīng)完成了,下一節(jié)會講解helloworldweb Bundle,涉及Import Package,OSGi的啟動,Spring+Web的配置等

          專注于Java,數(shù)據(jù)庫性能,Web Server負(fù)載,數(shù)據(jù)挖掘,機(jī)器學(xué)習(xí)等方向
          posted on 2011-09-18 21:13 柳桐 閱讀(2352) 評論(1)  編輯  收藏 所屬分類: Java

          評論:
          # re: [OSGi] OSGi + Spring + Web Demo [1] 2011-09-19 08:53 | tb
          先收藏了   回復(fù)  更多評論
            

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 五指山市| 龙江县| 梧州市| 内乡县| 台湾省| 孝感市| 辽中县| 同心县| 丽水市| 托里县| 财经| 阳城县| 辽中县| 扶余县| 珲春市| 新郑市| 诸暨市| 满洲里市| 凌源市| 镶黄旗| 城市| 惠来县| 获嘉县| 长春市| 长治县| 长顺县| 九江县| 秦安县| 美姑县| 长春市| 汶川县| 蛟河市| 济源市| 佛坪县| 桦南县| 宁都县| 石首市| 红安县| 长葛市| 临朐县| 凤冈县|