使用新的 1.0 版本 JavaMoney API与 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 接口(interface)“从不”触发加载本地资源(而不是远程资源),但我也尝试过“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());
}
这与方法中“ONSTARTUP”的情况相同 registerData在 DefaultLoaderService :
switch (updatePolicy) {
case NEVER:
loadDataLocal(resourceId);
break;
case ONSTARTUP:
loadDataAsync(resourceId);
break;
case SCHEDULED:
addScheduledLoad(res);
break;
case LAZY:
default:
break;
}
这是否是无论我在 javamoney.properties 中放入什么它都会加载的原因?
我们如何完全关闭其他 ExchangeRateProvider?我们只想使用我们的自定义 ExchangeRateProvider .
最佳答案
看来我们这里有问题。您能否在我们的 java.net/javamoney 项目中提交 Jira 问题(并检查是否已提交此问题 :))。我们计划在接下来几天发布 ri 的补丁版本,因此我们也可能会修复此问题。
非常感谢! 阿纳托尔
关于java - 覆盖 javamoney.properties 中的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30931631/