owner icon indicating copy to clipboard operation
owner copied to clipboard

Property sources in parent interface are not inherited

Open abysas opened this issue 10 years ago • 2 comments

I wanted to split configuration interfaces which would share the same property sources and their loading/merging strategy. For that I wanted to define parent interface specifying those sources. Unfortunately in that case the properties are not loaded.

For example, I have parent interface which specifies sources to property files:

@Config.LoadPolicy(Config.LoadType.MERGE)
@Config.Sources({"classpath:application.properties",
        "classpath:application.conf",
        "classpath:reference.conf"})
public interface BaseConfig extends Config {

    void list(PrintStream out);
}

and sub interface which extends the parent:

public interface PdfApiConfig extends BaseConfig {

    @Config.Key("pdfapi.copyUnmodified")
    boolean isCopyUnmodified();
}

I have property file reference.conf containing value: pdfapi.copyUnmodified=true

And this code fails with NPE, unless I repeat @Config.Sources annotation on subinterface:

PdfApiConfig config = ConfigFactory.create(PdfApiConfig.class);
boolean value = config.isCopyUnmodified();

abysas avatar Jun 18 '15 09:06 abysas

Hi @abysas, this can be surely improved, but I think it is correct to specify the @Sources annotation in the sub interface. I could add the ability to include the @Sources from the super interface too as improvement.

Thank you.

lviggiano avatar Jun 18 '15 10:06 lviggiano

@lviggiano, that would be great and IMHO it would allow to follow "don't repeat yourself" principle, don't you think :)

I guess such behavior could be default, unless subinterfaces were annotated with @Sources as well, which would effectively override the sources in super interface.

abysas avatar Jun 18 '15 11:06 abysas