我有很多通过 RMI 和 Spring 公开的服务。目前,我的应用程序配置为 Web 应用程序,并将我的应用程序部署到 JBoss 以使我的 RMI 服务可用。有没有一种方法可以运行我的 RMI 公开服务,而无需将我的应用程序设为 Web 应用程序?
最佳答案
是的,只需在“普通”(读取:非 webapp)应用程序中实例化您的 Spring 应用程序上下文并为其定义您的服务和导出器:
<bean id="myService" class="my.example.MyServiceImpl">
<!-- properties -->
</bean>
<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="myRMIService"/>
<property name="service" ref="myService"/>
<property name="serviceInterface" value="my.example.MyService"/>
<!-- defaults to 1099 -->
<property name="registryPort" value="1199"/>
</bean
这样您的服务将在 rmi://HOST:1199/myRMIService
上可用。
关于 Spring RMI : How to expose without App server or servlet container?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6389076/