首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在httpserver (Spring )的上下文属性中添加OSGI服务引用?

如何在httpserver (Spring )的上下文属性中添加OSGI服务引用?
EN

Stack Overflow用户
提问于 2013-09-11 17:41:39
回答 2查看 685关注 0票数 0

我使用和OSGI。

代码语言:javascript
复制
   <bean id="httpServer" class="org.springframework.remoting.support.SimpleHttpServerFactoryBean">
        <property name="contexts">
        <util:map>
            <entry key="/remoting/Service1" value-ref="serviceBean1"/>
        </util:map>
        </property>
        <property name="port" value="8080" />
   </bean>   

我宣布一份动态清单如下:

代码语言:javascript
复制
<osgi:list id="serviceList" interface="com.xyz.IRemoteService" member-type="service-object">

现在,这些服务可以动态注册。在某个时候,serviceList将保存实现com.xyz.IRemoteService的所有服务引用。如何将此服务列表设置为“上下文”属性?

更新1 :

com.xyz.IRemoteService有两种方法,一种是返回键,即url,另一种是返回我将配置更改为as的SimpleHttpInvokerServiceExporter object.So。

代码语言:javascript
复制
<bean id="httpServer" class="org.springframework.remoting.support.SimpleHttpServerFactoryBean">
    <property name="contexts">
        <util:map>
        <entry key="/remoting/ArchiveEDSImpl" value-ref="archiveEDS" />
        <entry key="#{serviceList[0].url}" value="#{serviceList[0].httpHandler}" />
        <entry key="#{serviceList[1].url}" value="#{serviceList[1].httpHandler}" />
        </util:map>
    </property>
    <property name="port" value="8081" />
</bean>

<osgi:list id="serviceList" interface="com.xyz.IRemoteServiceProvider" member-type="service-object">
</osgi:list>

这很好,但只有在初始化bean httpserver时,serviceReferenceList中至少有2个元素才能工作。如何根据列表中的大小动态配置??

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-16 14:10:21

谢谢你的回复,希娜。事实证明,SimpleHttpServerFactoryBean保存的是地图的副本,而不是引用。因此,当bean被初始化时,contexts属性将是设置,我找不到任何其他方法来更新它。

作为一种解决方法,我必须刷新SimpleHttpServerFactoryBean bean初始化的包。

如果有更好的解决办法,请告诉我。

票数 0
EN

Stack Overflow用户

发布于 2013-09-13 21:20:00

您可以不使用util: Map,而是定义一个工厂或bean,它连接在IRemoteServiceProvider中并输出一个Map。

代码语言:javascript
复制
class MyMapFactory {
  List<IRemoteServiceProvider> providers;
  public Map buildMap() {
    //build Map of urls to http handlers here.
    // if the map wraps the list directory it can possibly even be dynamic! Depending on
    // whether SimpleHttpServerFactoryBean clones the map or uses it directly.
  }
}

<bean class="MyMapFactory" id="myMapFactory"/>

<bean id="httpServer" class="org.springframework.remoting.support.SimpleHttpServerFactoryBean">
  <property name="contexts">
    <bean factory-bean="myMapFactory" factory-method="buildMap" class="java.util.Map"/> 
  </property>
  <property name="port" value="8081" />
</bean>

<osgi:list id="serviceList" interface="com.xyz.IRemoteServiceProvider" member-type="service-   object">
</osgi:list>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18747845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档