杞澆璇鋒敞鏄庡嚭澶?http://www.aygfsteel.com/fireflyk/archive/2011/09/18/358922.html
緗戜笂鎵句簡寰堝渚嬪瓙錛岀湅浜嗗緢澶氳祫鏂欏彂鐜伴兘涓嶈兘瀹屽叏閲嶇幇涓涓狾SGi鐨刉eb Demo
鏈枃緇撳悎浜嗐奜SGi鍘熺悊涓庢渶浣沖疄璺點?鍏徃鍚屼簨鐨勩奜SGi寮鍙戙?鑷繁鐨勭悊瑙c?br />
鐜WindowXP + eclipse3.4 + Spring OSGi1.2.1
1. 鍒涘緩timeservice Bundle錛屾彁渚涜緭鍑烘椂闂寸殑鍔熻兘
1.1 eclipse鍐呭垱寤篗aven Project錛岄塹uickstart project錛歵imeservice錛宲ackage org.osgichina.demo.timeservice
1.2 鍒涘緩濂藉悗錛宺emove maven鐨刯ar鍖咃紝鍒犳帀project涓殑App鍜孉ppTest錛屽湪欏圭洰涓婂彸閿?>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鐩綍涓嬶紝妗嗘灦鍚姩鏃朵細鎸夌収榪欎釜璺緞鍘誨鎵鵑厤緗枃浠?br />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">
<!-- 灝唗imeService 榪欎釜bean鍙戝竷涓篛SGi鏈嶅姟鐨勫畾涔?/span>-->
<osgi:service id="osgiTimeService" ref="timeService" interface="org.osgichina.demo.timeservice.TimeService">
</osgi:service>
</beans>
榪欎釜Bundle鍒版宸茬粡瀹屾垚浜嗭紝涓嬩竴鑺備細璁茶Вhelloworldweb Bundle錛屾秹鍙奍mport Package錛孫SGi鐨勫惎鍔紝Spring+Web鐨勯厤緗瓑
]]>