0

我正在尝试在此处完善示例代码

http://xeiam.com/xchange_examplecode.jsp

  public static void main(String[] args) {

    // Demonstrate the public market data service
    // Use the factory to get the version 2 MtGox exchange API using default settings
    Exchange mtGoxExchange = ExchangeFactory.INSTANCE.createExchange(MtGoxExchange.class.getName());

    // Interested in the public market data feed (no authentication)
    PollingMarketDataService marketDataService = mtGoxExchange.getPollingMarketDataService();

基本上,我希望将 PollingMarketDataService 或 Exchange 作为 spring bean 注入。

但是上面的 ExchangeFactory 是一个枚举,当我尝试这个时:

<beans:bean id="exchangeFactory" class="com.xeiam.xchange.ExchangeFactory" factory-method="valueOf">
    <beans:constructor-arg value="INSTANCE"/>
</beans:bean>

<beans:bean id="mtGoxExchange" factory-bean="exchangeFactory" factory-method="createExchange">
    <beans:constructor-arg value="com.xeiam.xchange.mtgox.v2.MtGoxExchange"/>
</beans:bean>

ExchangeFactory 为空。

4

1 回答 1

5

这应该有效:

<util:constant id="exchangeFactory" static-field="com.xeiam.xchange.ExchangeFactory.INSTANCE" />

<bean id="mtGoxExchange" factory-bean="exchangeFactory" factory-method="createExchange">
    <constructor-arg value="com.xeiam.xchange.mtgox.v2.MtGoxExchange" />
</bean>

试一试。

于 2013-06-04T20:44:20.447 回答