我使用Spring remoting和OSGI。
<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>我声明了一个动态列表如下:
<osgi:list id="serviceList" interface="com.xyz.IRemoteService" member-type="service-object">现在可以动态注册这些服务。 在某个时间点,serviceList将保存实现com.xyz.IRemoteService的所有服务引用。 如何将此服务列表设置为contexts属性?
更新1:
com.xyz.IRemoteService有两个方法,一个返回密钥,即url,另一个返回SimpleHttpInvokerServiceExporter对象。所以我将配置更改为as
<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个元素才有效。 如何根据列表中的大小动态配置?
I use Spring remoting and OSGI.
<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>I declare an dynamic list as below :
<osgi:list id="serviceList" interface="com.xyz.IRemoteService" member-type="service-object">Now these services can be registered dynamically. At one point of time serviceList will hold all the service references implementing com.xyz.IRemoteService. How can I set this service list to the contexts property?
Update 1 :
The com.xyz.IRemoteService has two methods one which returns the key i.e. the url and the other returns the SimpleHttpInvokerServiceExporter object.So I changed teh configurations to as
<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>This is great but works only if there are at least 2 elements in the serviceReferenceList when bean httpserver is initialized. How do I configure this dynamically based on the size in the list ??
最满意答案
您可以,而不是使用util:map,定义在IRemoteServiceProvider中连接并输出Map的工厂或bean。
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>Thanks for the reply Sheena. It turns out that SimpleHttpServerFactoryBean holds a copy of the Map and not the reference. So contexts property will be the set when the bean is being initialized.I could not find any other way to update it.
As a workaround I had to refresh the bundle in which the SimpleHttpServerFactoryBean bean is initialized.
Please let me know if there is a better solution.
更多推荐
serviceList,IRemoteService,电脑培训,计算机培训,IT培训"/> <meta name="de
发布评论