覆盖javamoney.properties中的属性?

时间:2015-06-19 06:45:05

标签: java jsr354 java-money

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界面'永远'触发器加载本地资源(而不是远程),但我也尝试了“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中添加什么内容,这都可能是加载的原因吗?

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

1 个答案:

答案 0 :(得分:4)

我们这里有一个问题。你能否在我们的java.net/javamoney项目中提出一个Jira问题(并检查这个问题是否已经提交:))。我们计划在下一天发布ri的补丁版本,所以我们也可以解决这个问题。

非常感谢! 阿纳托利