我在 Spring 上使用 RMI 公开了一些服务。每个服务都依赖于执行实际处理工作的其他服务 bean。例如:
<bean id="accountService" class="example.AccountServiceImpl">
<!-- any additional properties, maybe a DAO? -->
</bean>
<bean id="rmiAccount" class="example.AccountRmiServiceImpl"/>
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<!-- does not necessarily have to be the same name as the bean to be exported -->
<property name="serviceName" value="AccountService"/>
<property name="service" ref="accountService"/>
<property name="serviceInterface" value="example.AccountService"/>
<!-- defaults to 1099 -->
<property name="registryPort" value="1199"/>
</bean>
我的 AccountRmiServiceImpl 看起来像这样:
public class AccountRmiServiceImpl implements AccountRmiService {
private static final long serialVersionUID = -8839362521253363446L;
private AccountService accountService;
@Autowired
public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}
}
我的问题是:可以AccountServiceImpl
在不实现Serializable
标记接口的情况下创建吗?如果是这种情况,那么它的引用AccountRmiServiceImpl
应该是暂时的。这意味着它不会被序列化并传输到进行 RMI 调用的客户端。是否可以?