原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处 、作者信息和本声明。否则将追究法律责任。
http://killko.blog.51cto.com/3419292/1131103
- <?xml version="1.0" encoding="UTF-8"?>
- <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd" default-timeout="0">
- <!--最简单的osgi服务注册 -->
- <bean id="coder" class="com.ponder.CoderImpl"/>
- <service id="CoderService" ref="coder" interface="com.ponder.ICoder"/>
- <!--Embeded bean的osgi服务注册 -->
- <service id="CoderService2" interface="com.ponder.ICoder">
- <bean class="com.ponder.CoderImpl"/>
- </service>
- <!--带osgi服务属性的服务-->
- <service id="CoderService3" interface="com.ponder.ICoder">
- <service-properties>
- <entry key="param01" value="val01"/>
- <entry key="param02" value="val02"/>
- <entry key="param03">
- <array value-type="java.lang.String">
- <value>val03-1</value>
- <value>val03-2</value>
- <value>val03-3</value>
- </array>
- </entry>
- </service-properties>
- <bean class="com.ponder.CoderImpl"/>
- </service>
- <!-- 没将接口抽离出来的osgi服务,会将com.ponder.CoderImpl里的所有public方法都作为服务的方法 -->
- <service id="CoderService3" interface="com.ponder.CoderImpl">
- <bean class="com.ponder.CoderImpl"/>
- </service>
- </blueprint>
- <?xml version="1.0" encoding="UTF-8"?>
- <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd" default-timeout="0">
- <!--引用osgi服务,并注入bean(com.ponder.Processor)里 -->
- <reference id="coderService" filter=”(param01=val02)” interface="com.ponder.ICoder" timeout="0"/>
- <bean id="processor" class="com.ponder.Processor">
- <!--与这里对应,类com.ponder.Processor里应定义有以下属性:
- private com.ponder.ICoder coder;
- 并包含其setter。
- -->
- <property name="coder" ref="coderService"/>
- </bean>
- </blueprint>