覆盖javamoney.properties中的属性?

Tru*_*uls 6 java jsr354 java-money

使用新的1.0版JavaMoney API参考实现,我们尝试通过覆盖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
Run Code Online (Sandbox Code Playgroud)

但是,日志告诉我它们仍然被加载:

jun 19, 2015 8:27:58 AM  org.javamoney.moneta.internal.convert.AbstractECBRateProvider newDataLoaded
INFO: Loaded ECBCurrentRateProvider exchange rates for days:1
Run Code Online (Sandbox Code Playgroud)

从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
}
...
Run Code Online (Sandbox Code Playgroud)

我们注意到在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());
}
Run Code Online (Sandbox Code Playgroud)

这与DefaultLoaderService中方法registerData中的情况'ONSTARTUP'相同:

switch (updatePolicy) {
        case NEVER:
            loadDataLocal(resourceId);
            break;
        case ONSTARTUP:
            loadDataAsync(resourceId);
            break;
        case SCHEDULED:
            addScheduledLoad(res);
            break;
        case LAZY:
        default:
            break;
    }
Run Code Online (Sandbox Code Playgroud)

这可能是一个原因,无论我放在我的javamoney.properties中它是什么?

我们如何完全关闭其他ExchangeRateProviders?我们只想使用我们的自定义ExchangeRateProvider.

小智 5

看起来我们这里有问题。您能否在我们的java.net/javamoney项目中提交一个Jira问题(并检查是否已经提交了此问题:))。我们计划在第二天发布ri的修补程序版本,因此我们也可能会对此进行修复。

非常感谢!Anatole