Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can try <a href="http://owner.aeonbits.org" rel="nofollow">OWNER API</a>: it supports 3 levels of properties overriding, and it also provides mapping between a Java object and properties files and other neat features.</p> <p>The first overriding capability is the specification of the default value on the mapping interface:</p> <pre><code>public interface ServerConfig extends Config { @DefaultValue("42") int maxThreads(); } </code></pre> <p>ServerConfig gets mapped by default to ServerConfig.properties in the same package. If the property "maxThreads" is not specified, then 42 is used as default (the properties files overrides the DefaultValue).</p> <p>The second overriding capability is the possibility to specify multiple properties file locations for the class, so the first resource found is used. This way you define an internal properties in your jar, and allow the user to specify an overriding properties file in his home directory or in /etc/myapp, or everywhere else you prefer:</p> <pre><code>@Sources({ "file:~/.myapp.config", "file:/etc/myapp.config", "classpath:foo/bar/baz.properties" }) public interface ServerConfig extends Config { @Key("server.http.port") int port(); @Key("server.host.name") String hostname(); @Key("server.max.threads"); @DefaultValue("42") int maxThreads(); } </code></pre> <p>The third overriding capability is to specify that you want all of the above file being considered but you want the override to happen to a property level, so that if all the above properties file are available, when you ask for the property <code>maxThreads()</code>, this will be searched first in <code>file:~/.myapp.config</code> - if not found - then in <code>file:/etc/myapp.config</code> and then in <code>classpath:foo/bar/baz.properties</code>, and as last resort the <code>@DefaultValue("42")</code> applies, then you specify to the library that it has to produce a <em>merge</em> of all the properties resources (and consider them all)</p> <pre><code>@LoadPolicy(LoadType.MERGE) @Sources({ "file:~/.myapp.config", "file:/etc/myapp.config", "classpath:foo/bar/baz.properties" }) public interface ServerConfig extends Config { // same content as above. } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload