Announcement Announcement Module
Collapse
No announcement yet.
prototype RmiProxyFactoryBean with different serviceUrl Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • prototype RmiProxyFactoryBean with different serviceUrl

    Hi,

    I'm quite new to Spring and i'm trying to use RmiProxyFactoryBean. My requirements are quite odd, but i have currently no other way to do that...

    I have a service interface exposed with RMI, let's say rmi.Calc (with a add(int,int) method). The application creates a new JVM instance (java.exe) which launches a RMI server (thanks to Spring) that expose a new Calc service customized by some parameters on the command line.

    This part is managed by this:

    Code:
    <beans ...>
        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
        <bean name="calc" class="rmi.CalcImpl" />
    
        <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
            <property name="serviceName" value="CalcService-${serviceName}" />
            <property name="service" ref="calc" />
            <property name="serviceInterface" value="rmi.Calc" />
        </bean>
    </beans>
    Then the application needs to use the services. The following works for a static URL:

    Code:
    <beans ...>
        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
    
        <bean id="calc" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
            <property name="serviceUrl" value="rmi://localhost:1099/CalcService-${serviceName}" />
            <property name="serviceInterface" value="rmi.Calc" />
        </bean>
    </beans>
    To have something that i can customize at runtime i tried the following which works :

    Code:
    RmiProxyFactoryBean bean = new RmiProxyFactoryBean();
    bean.setServiceInterface(Calc.class);
    bean.setServiceUrl("rmi://localhost:1099/CalcService-123");
    bean.afterPropertiesSet();
    
    Calc calc = (Calc) ((FactoryBean) bean).getObject();
    
    System.out.println(calc.add(1, 2));
    but i am quite curious to know if there is something better than that, since i guess this kind of problem may occasionally arise.

    Thanks

    David
Working...
X