简体   繁体   English

基于Spring注释的SAP连接器

[英]Spring annotation based SAP connector

I'm trying to move from a xml based config to java annotations 我正在尝试从基于xml的配置转移到Java批注

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? 显然,我无法将RemoteJco接口设置为我的SapConnector,但是如何使该xml-config工作呢?

@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: 在XML-Config中可以正常工作:

<!-- 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 这是我的SAP连接器

@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: 您必须对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. 而且您必须在调用RmiProxyFacotoryBean实例上的getObject之前调用afterPropertiesSet()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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