spring osgi helloworld
- 1.准备环境:
下载felix,
运行felix.jar:org.apache.felix.main.Main函数
如何加入spring osgi -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/lib/slf4j-api-1.4.3.jar -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/lib/jcl104-over-slf4j-1.4.3.jar -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/lib/spring-core-2.5.1.jar -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/lib/spring-beans-2.5.1.jar -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/lib/spring-context-2.5.1.jar -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/lib/spring-aop-2. -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/lib/aopalliance.osgi-1.0-SNAPSHOT.jar5.1.jar -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/dist/spring-osgi-core-1.0.2.jar -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/dist/spring-osgi-extender-1.0.2.jar -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/dist/spring-osgi-io-1.0.2.jar test (the spring samples service):以下测试见2,3步骤 -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/src/samples/simple-service/simple-service-bundle/target/simple-service-bundle-1.0.2.jar -> start file:///home/jiangyy/workspace/spring-osgi-1.0.2/src/samples/simple-service/simple-service-bundle/target/simple-service-bundle-1.0.2.test.jar
2.定义服务:
下载spring-osgi包,找到sample/simpleservice,到src相对应目录下,运行:
mvn clean install,打包后将生成:
simple-service-bundle-1.0.2.jar
这个可以注册了
3.在其他jar 服务中注入服务
如何在其他jar中注入MyService实现:
写了个类,相当于spring bean,然后把刚才打好的包拷贝,改成以下的class文件,
package org.springframework.osgi.samples.simpleservicetest;
import org.springframework.osgi.samples.simpleservice.MyService;
public class MyTest {
public void setMyService(MyService service) {
System.out.println("invokeing");
System.out.println(service.stringValue());
System.out.println("end");
}
}
在 MANIFEST.MF中引入 需要的包 。在META-INF中添加spring /bean.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">
<osgi:reference id="simpleServiceOsgi" interface="org.springframework.osgi.samples.simpleservice.MyService"/>
<bean id="testEntityRegister" class="org.springframework.osgi.samples.simpleservicetest.MyTest">
<property name="myService" ref="simpleServiceOsgi" />
</bean>
</beans>
spring sampleservice的MANIFEST.MF文件:
Bundle-Version: 1.0 Bundle-SymbolicName: org.springframework.osgi.samples.simpleservice Bundle-Name: Simple-Service-Sample Bundle-Vendor: Spring Framework Export-Package: org.springframework.osgi.samples.simpleservice Bundle-ManifestVersion: 2
META-INF/springsample.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">
<!-- regular spring configuration file defining simple service
bean. We've kept the osgi definitions in a separate
configuration file so that this file can easily be used
for testing outside of an OSGi environment -->
<bean name="simpleService" class="org.springframework.osgi.samples.simpleservice.impl.MyServiceImpl" />
<osgi:service id="simpleServiceOsgi" ref="simpleService"
interface="org.springframework.osgi.samples.simpleservice.MyService" />
</beans>
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 10750 次
- 性别:

- 来自: 广州

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
gwt spring 完美整合
gwt前端定义一个异常类 public class ApplicationExc ...
-- by yongyuan.jiang -
gwt spring 完美整合
(gwt+spring)我想用aop拦截来判断session超时,但是我怎样才能 ...
-- by angeltping -
GWT HTML Template :模板 ...
hehe,HTMLTemplatePanel增强功能,gwt类直接获得模板页面对 ...
-- by yongyuan.jiang -
Gwt 服务端使用hiberante ...
能说说都有哪些问题?为什么产生?如何解决? 正打算在一个GWT项目的服务器端使用 ...
-- by abo -
gwt spring 完美整合
博主是javaeye上的gwt第一高人,特别希望博主可以就如何用gwt开发一个伸 ...
-- by abo






评论排行榜