这个 inject 没看懂。注入了什么东西?
@Inject
public PriceService....{
super(supportedCurrencies);
}
@Inject
public PriceService....{
super(supportedCurrencies);
}
2017-10-20
注入的是支持的货币类型,是一个set类型
定义module绑定
package org.demo.guicedemo.server.impl; import com.google.inject.AbstractModule; import com.google.inject.multibindings.Multibinder; public class ChinaModule extends AbstractModule { @Override protected void configure() { // Adds CNY support Multibinder.newSetBinder(binder(), String.class) .addBinding().toInstance("CNY"); } }
就会往集合中添加值CNY
package org.demo.guicedemo.server.impl; import com.google.inject.AbstractModule; import com.google.inject.multibindings.Multibinder; public class GlobalModule extends AbstractModule { @Override protected void configure() { // Adds EUR, USD support Multibinder<String> currencyBinder = Multibinder.newSetBinder(binder(), String.class); currencyBinder.addBinding().toInstance("EUR"); currencyBinder.addBinding().toInstance("USD"); } }
就会往集合中添加值EUR和USD
举报