简体   繁体   中英

Spring annotation based SAP connector

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;
}
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM