0

I'm trying to move from a xml based config to java annotations

I need your help getting this to work:

Obviously I can't set the RemoteJco interface to my SapConnector but what can I do to get this xml-config working?

@Bean
public RmiProxyFactoryBean jcoPool(){
    RmiProxyFactoryBean jcoPool = new RmiProxyFactoryBean();
    jcoPool.setServiceUrl("rmi://localhost/CH");
    jcoPool.setServiceInterface(RemoteJco.class);
    jcoPool.setRefreshStubOnConnectFailure(true);
    return jcoPool;
}

@Bean
public SapConnector SapConnector(){
    SapConnector sapConnector = new SapConnector();
    sapConnector.setJcoPool(jcoPool());
    return sapConnector;
}

this in the XML-Config works just fine:

<!-- JCO-Pool RMI Service -->
<bean id="jcoPool" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
    <property name="serviceUrl" value="rmi://localhost/CH"/>
    <property name="serviceInterface" value="com.itensis.jco.common.RemoteJco"/>
    <property name="refreshStubOnConnectFailure" value="true" />
</bean>

<bean id="SapConnector" class="com.itensis.core.SapConnector">
    <property name="jcoPool">
        <ref bean="jcoPool" />
    </property>
</bean>

this is my SAP-Connector

@Service
public class SapConnector {
@Autowired private RemoteJco jcoPool;


public RemoteJco getJcoPool() {
    return jcoPool;
}

public void setJcoPool(RemoteJco jcoPool) {
    this.jcoPool = jcoPool;
}
}
James Carter
  • 849
  • 3
  • 13
  • 29

1 Answers1

1

You have to make some changes on the jcoPool bean:

@Bean
public RemoteJco jcoPool(){
    RmiProxyFactoryBean jcoPool = new RmiProxyFactoryBean();
    jcoPool.setServiceUrl("rmi://localhost/CH");
    jcoPool.setServiceInterface(RemoteJco.class);
    jcoPool.setRefreshStubOnConnectFailure(true);
    jcoPool.afterPropertiesSet();
    return (RemoteJco) jcoPool.getObject();
}

Make sure that you return value has the same class as you used as service interface. And you have to call afterPropertiesSet() before calling getObject on the RmiProxyFacotoryBean instance.