使用
JavaMoney API的新1.0版本和
reference implementation,我们尝试通过覆盖javamoney.properties来阻止资源加载器加载其他ExchangeRateProvider.
{1}conversion.default-chain=MY-PROVIDER
# Turn off loading of the default Moneta ExchangeRateProviders.
{1}load.ECBCurrentRateProvider.type=NEVER
{1}load.ECBHistoric90RateProvider.type=NEVER
{1}load.ECBHistoricRateProvider.type=NEVER
{1}load.IMFRateProvider.type=NEVER
{1}load.AbstractECBRateProvider=NEVER
但是,日志告诉我它们仍然被加载:
jun 19, 2015 8:27:58 AM org.javamoney.moneta.internal.convert.AbstractECBRateProvider newDataLoaded
INFO: Loaded ECBCurrentRateProvider exchange rates for days:1
从LoaderService接口’NEVER’触发加载本地资源(而不是远程),但我也试过’LAZY’.
public interface LoaderService {
/**
* Platform RI: The update policy defines how and when the
* {@link LoaderService} tries to update the local cache with newest version of
* the registered data resources, accessing the configured remote
* {@link URI}s. By default no remote connections are done (
* {@link UpdatePolicy#NEVER} ).
*
* @author Anatole Tresch
*/
public enum UpdatePolicy {
/**
* The resource will never be updated from remote, only the fallback URL
* will be evaluated.
*/
NEVER,
/**
* The resource will be loaded automatically from remote only once on
* startup.
*/
ONSTARTUP,
/**
* The resource will be loaded automatically from remote only once, when
* accessed the first time.
*/
LAZY,
/**
* The resource should be regularly reloaded based on a schedule.
*/
SCHEDULED
}
...
我们注意到在org.javamoney.moneta.internal.convert中的ExchangeProviders的构造函数中,有一个对loader.loadDataAsync的调用:
AbstractECBRateProvider(ProviderContext context) {
super(context);
saxParserFactory.setNamespaceAware(false);
saxParserFactory.setValidating(false);
LoaderService loader = Bootstrap.getService(LoaderService.class);
loader.addLoaderListener(this, getDataId());
loader.loadDataAsync(getDataId());
}
switch (updatePolicy) {
case NEVER:
loadDataLocal(resourceId);
break;
case ONSTARTUP:
loadDataAsync(resourceId);
break;
case SCHEDULED:
addScheduledLoad(res);
break;
case LAZY:
default:
break;
}
这可能是一个原因,无论我放在我的javamoney.properties中它是什么?
我们如何完全关闭其他ExchangeRateProviders?我们只想使用我们的自定义ExchangeRateProvider.