RmiProxyFactoryBean +自动连线(必需= false)
我有 5 个项目 - 其中 4 个在控制台上运行(例如 A、B、C 和 D),使用 java -jar A.jar 等和 1 个 Web 应用程序 (E)。 Web 应用程序部署在许多独立的服务器上,其中一些服务器还同时运行 A、B、C 和 D 的组合。
在 Web 应用程序的 spring 配置文件中,我有 4 个 RmiProxyFactoryBean 声明,每个项目 A、B、C 和 D 各有一个声明,其中每个项目都有 1 个 RmiServiceExporter 。
我的问题是,如果其中一个项目 (AD) 未运行,则 Web 应用程序在启动时会引发异常。我尝试在使用这些服务的控制器中使用 @Autowired(required=false)
但无济于事。为了使其工作,我必须去编辑 Web 应用程序 spring 文件,以注释掉未运行的项目的 RmiProxyFactoryBean。有没有一种方法可以告诉 RmiProxyFactoryBean 尝试检索 bean,如果失败,请不要担心 - 与使用 autowire 的 required=false 非常相似?
我的配置目前如下所示:
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="diagramAssociationService" />
<property name="serviceName" value="diagramAssociationService"/>
<property name="serviceInterface" value="com.act.xv.service.IDiagramAssociationService"/>
</bean>
和
<bean id="diagramAssociationService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://${xv.deploy.location}/diagramAssociationService"/>
<property name="serviceInterface" value="com.act.xv.service.IDiagramAssociationService"/>
<property name="refreshStubOnConnectFailure" value="true" />
</bean>
I have 5 projects - 4 of which are run on the console (say A,B,C and D) with java -jar A.jar
etc and 1 web application (E). The web application is deployed on a number of isolated servers some of which also have a combination of A, B, C and D running.
In the spring config file for the web application I have 4 RmiProxyFactoryBean
declarations, one for each of the projects A, B, C and D where each of these projects have 1 RmiServiceExporter
.
My problem is that the web application throws an exception on startup if one of the projects (A-D) is not running. I've tried using @Autowired(required=false)
in the controllers using these services to no avail. To make it work I'm having to go edit the web app spring file to comment out the RmiProxyFactoryBean
for projects that aren't running. Is there a way of telling an RmiProxyFactoryBean
to attempt to retrieve the bean and if it fails then don't worry - in much a similar way as required=false
with the autowire?
My config currently looks like this:
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="diagramAssociationService" />
<property name="serviceName" value="diagramAssociationService"/>
<property name="serviceInterface" value="com.act.xv.service.IDiagramAssociationService"/>
</bean>
and
<bean id="diagramAssociationService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://${xv.deploy.location}/diagramAssociationService"/>
<property name="serviceInterface" value="com.act.xv.service.IDiagramAssociationService"/>
<property name="refreshStubOnConnectFailure" value="true" />
</bean>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 RmiProxyFactoryBean 中还将lookupStubOnStartup 属性设置为“false”。这应该可以防止客户端代理在启动时抛出异常。
In your RmiProxyFactoryBean also set the lookupStubOnStartup property to "false". This should prevent the client proxy from throwing an exception on startup.