Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property sources in parent interface are not inherited #128

Open
abysas opened this issue Jun 18, 2015 · 2 comments
Open

Property sources in parent interface are not inherited #128

abysas opened this issue Jun 18, 2015 · 2 comments

Comments

@abysas
Copy link

abysas commented Jun 18, 2015

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 abysas changed the title Property sources in parent interfaces are not inherited Property sources in parent interface are not inherited Jun 18, 2015
@lviggiano
Copy link
Collaborator

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.

@abysas
Copy link
Author

abysas commented Jun 18, 2015

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants