Code:
<bean id="feisService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl"><value>rmi://xyz:1099/FeisService</value></property>
<property name="serviceInterface"><value>com.xyz.feissync.FeisService</value></property>
</bean>
<bean id="feisSynchronizer" class="com.xyz.feissync.FeisSynchronizerImpl">
<property name="feisService"><ref local="feisService"/></property>
</bean>
public class FeisSynchronizerImpl implements FeisSynchronizer, ApplicationContextAware {
private ApplicationContext ac;
private FeisService feisService;
public void setApplicationContext(ApplicationContext ac) throws BeansException {
this.ac = ac;
}
public void setFeisService(FeisService feisService) {
this.feisService = feisService;
}
public void syncFeisContracts() {
List feisContracts = null;
int repeatCount = 0;
while (repeatCount <= 1) {
repeatCount++;
try {
feisContracts = feisService.findContractsModifiedSince(lastUpdateDate);
} catch (RemoteException ex) {
log.warn(ex);
log.info("Trying to obtain new feisService from application context");
InitializingBean factory = (InitializingBean)ac.getBean("&feisService");
try {
factory.afterPropertiesSet(); // rebind remote server
feisService = (FeisService)ac.getBean("feisService");
} catch (Exception ex2) {
log.warn(ex2);
}
}
}
}
}