javaspringrmidependency-managementspring-remoting

RmiProxyFactoryBean + Autowired(required=false)


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>

Solution

  • In your RmiProxyFactoryBean also set the lookupStubOnStartup property to "false". This should prevent the client proxy from throwing an exception on startup.