We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
@Key
Example:
<servers> <dev> <!-- development environment --> <name>DEV</name> <hostname>devhost</hostname> <port>6000</port> <user>myuser1</user> <password>mypass1</password> </dev> <uat> <!--- user acceptance test environment --> <name>UAT</name> <hostname>uathost</hostname> <port>60020</port> <user>myuser2</user> <password>mypass2</password> </uat> </servers>
Mapping class and example usage:
@Sources("classpath:org/aeonbits/owner/variableexpansion/KeyExpansionExample.xml") public interface ExpandsFromAnotherKey extends Config { @DefaultValue("dev") String env(); @Key("servers.${env}.name") String name(); @Key("servers.${env}.hostname") String hostname(); @Key("servers.${env}.port") Integer port(); @Key("servers.${env}.user") String user(); @DisableFeature(VARIABLE_EXPANSION) @Key("servers.${env}.password") String password(); } @Test public void testKeyExpansionFromAnotherKey() { ExpandsFromAnotherKey cfg = ConfigFactory.create(ExpandsFromAnotherKey.class); assertEquals("DEV", cfg.name()); assertEquals("devhost", cfg.hostname()); assertEquals(new Integer(6000), cfg.port()); assertEquals("myuser1", cfg.user()); assertNull(cfg.password()); // expansion is disabled on method level } @Test public void testKeyExpansionFromAnotherKeyWithImportOverriding() { ExpandsFromAnotherKey cfg = ConfigFactory.create(ExpandsFromAnotherKey.class, map("env", "uat")); assertEquals("UAT", cfg.name()); assertEquals("uathost", cfg.hostname()); assertEquals(new Integer(60020), cfg.port()); assertEquals("myuser2", cfg.user()); assertNull("mypass2", cfg.password()); // expansion is disabled on method level }
This way you can select ${env} in the ConfigFactory (or from the system properties) and have the above interface map to the appropriate section.
${env}
See: #56 #48
The text was updated successfully, but these errors were encountered:
implemente variable expansion in @key annotation. See issue #63.
6062b83
implemented variable expansion in @key annotation. See issue #63.
c5da9ec
Implemented few days ago, missing the docs still, before to close this task.
Sorry, something went wrong.
updated documentation on variable expension; Issue #63
20c903b
lviggiano
No branches or pull requests
Example:
Mapping class and example usage:
This way you can select
${env}
in the ConfigFactory (or from the system properties) and have the above interface map to the appropriate section.See: #56 #48
The text was updated successfully, but these errors were encountered: