我想知道Spring是否有任何解决方案来支持使用进程内服务或远程服务配置的过程调用。
更新1
一个例子,假设我们有以下内容:
共同项目:
public interface ServiceBInterface {
boolean doSomething();
}
项目A(取决于共同项目):
@Service
public class ServiceA {
@Autowired
private ServiceBInterface serviceB;
public void flowA() {
// run flow A code
boolean result = serviceB.doSomething();
// continue run flow A code with result of service B
}
}
项目B(取决于共同项目):
@Service
public class ServiceB implements ServiceBInterface {
public boolean doSomething() {
boolean result = false;
// execute some code
return result;
}
}
我希望能够在以下选项上配置ServiceBInterface bean:
答案 项目A(取决于共同项目):
@Service
public class ServiceA {
@Autowired
private ServiceBInterface serviceB;
@PostConstruct
public void init() {
if (Boolean.getBoolean("remote")) {
RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
rmiProxyFactoryBean.setServiceUrl("rmi://localhost:1099/ServiceB");
rmiProxyFactoryBean.setServiceInterface(ServiceBInterface.class);
rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
rmiProxyFactoryBean.setLookupStubOnStartup(false);
rmiProxyFactoryBean.afterPropertiesSet();
serviceB = (ServiceBInterface) rmiProxyFactoryBean.getObject();
}
}
public void flowA() {
// run flow A code
boolean result = serviceB.doSomething();
// continue run flow A code with result of service B
}
}
项目B(取决于共同项目):
@Service
public class ServiceB implements ServiceBInterface {
RmiServiceExporter rmiServiceExporte;
@PostConstruct
public void init() throws RemoteException {
if (Boolean.getBoolean("remoteB")) {
rmiServiceExporter = new RmiServiceExporter();
rmiServiceExporter.setServiceName("ServiceB");
rmiServiceExporter.setService(serviceB());
rmiServiceExporter.setServiceInterface(ServiceBInterface.class);
rmiServiceExporter.setServicePort(9999);
rmiServiceExporter.afterPropertiesSet();
}
}
public boolean doSomething() {
boolean result = false;
// execute some code
return result;
}
}
答案 0 :(得分:1)
对不起你的问题我不清楚,但我想知道你是否能够为自己阅读Spring Integration Reference Manual找到一些帮助。例如,有一个RMI支持,它表示为一对入站/出站网关,用于与远程过程服务进行通信。
否则,请更具体,特别是您希望获得的解决方案代码示例。