我正在尝试将这里的示例代码弹出
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是一个enum,当我尝试这个:
<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>
这应该可以工作:
<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>
试一试