Search code examples
springspring-remoting

Spring RMI: How to expose without App server or servlet container?


I have a bunch of services that I've exposed over RMI with Spring. Currently, my app is configured as a web app and I deploy my app to JBoss to make my RMI services available. Is there a way that I can run my RMI exposed services without having to make my app a web app?


Solution

  • Yes there is, just instantiate your Spring application context in a 'normal' (read: non-webapp) application and define your service and the exporter for it:

    <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
    

    This way your service will be available at rmi://HOST:1199/myRMIService.

    Read the full docs on RMI here. If you aren't familiar with how to instantiate a Spring context, read here.