Skip to content

Commit 1b5da1b

Browse files
authored
Merge pull request #132 from avaje/feature/improve-javadoc
Improve javadoc for Config and Configuration, include Builder example
2 parents deede18 + 479f251 commit 1b5da1b

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

avaje-config/src/main/java/io/avaje/config/Config.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,35 @@
1818
* Provides application Configuration based on loading properties and yaml files
1919
* as well as plugins that supply properties (like dynamic configuration loaded from a db).
2020
* <p>
21+
* The "Default" configuration automatically loads from known files and resources and
22+
* is available via {@link Config#asConfiguration()}. The methods on Config are convenience
23+
* methods that use the underlying "Default" configuration.
24+
* <p>
25+
* Refer to <a href="https://avaje.io/config/#loading">config loading</a> for details
26+
* on the "Default" configuration sources which include:
27+
* <ol>
28+
* <li> - application.properties & application.yaml resources & files</li>
29+
* <li> - system property load.properties</li>
30+
* <li> - command line arguments</li>
31+
* <li> - plugins (like the AWS AppConfig plugin)</li>
32+
* </ol>
33+
*
34+
* <p>
35+
* Configuration can also be built giving full control - refer to {@link Configuration#builder()}.
36+
*
37+
* <p>
2138
* The application can register onChange listeners to handle changes to configuration
2239
* properties at runtime. Plugins or code can dynamically load and change properties and
2340
* this can fire any registered callback handlers.
24-
* </p>
2541
*
26-
* <h3>Examples</h3>
42+
* <h3>Obtain the "default" configuration</h3>
43+
* <pre>{@code
44+
*
45+
* Configuration defaultConfiguration = Config.asConfiguration();
46+
*
47+
* }</pre>
48+
*
49+
* <h3>"Default" configuration usage examples</h3>
2750
* <pre>{@code
2851
*
2952
* int port = Config.getInt("app.port", 8090);
@@ -33,6 +56,27 @@
3356
* List<Integer> codes = Config.list().ofInt("my.codes", 42, 54);
3457
*
3558
* }</pre>
59+
*
60+
* <h3>Build a configuration</h3>
61+
* <pre>{@code
62+
*
63+
* var configuration = Configuration.builder()
64+
* .put("myKey", "myValue")
65+
* .load(someFile) // load a yaml or properties file
66+
* .load(someResource) // load a yaml or properties resource from the classpath
67+
* .build();
68+
*
69+
* }</pre>
70+
*
71+
* <h3>Use Configuration</h3>
72+
* <pre>{@code
73+
*
74+
* Configuration defaultConfiguration = Config.asConfiguration();
75+
*
76+
* int port = defaultConfiguration.getInt("port", 8080);
77+
* String host = defaultConfiguration.get("host", "localhost");
78+
*
79+
* }</pre>
3680
*/
3781
@NonNullApi
3882
public class Config {

avaje-config/src/main/java/io/avaje/config/Configuration.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,31 @@
1616
/**
1717
* Configuration API for accessing property values and registering onChange listeners.
1818
*
19-
* <h3>Examples</h3>
19+
* <h3>Obtain the "default" configuration</h3>
2020
* <pre>{@code
2121
*
22-
* int port = Config.getInt("app.port", 8090);
22+
* Configuration defaultConfiguration = Config.asConfiguration();
2323
*
24-
* String topicName = Config.get("app.topic.name");
24+
* }</pre>
25+
*
26+
* <h3>Build a configuration</h3>
27+
* <pre>{@code
28+
*
29+
* var configuration = Configuration.builder()
30+
* .put("myKey", "myValue")
31+
* .load(someFile) // load a yaml or properties file
32+
* .load(someResource) // load a yaml or properties resource from the classpath
33+
* .build();
34+
*
35+
* }</pre>
36+
*
37+
* <h3>Use Configuration</h3>
38+
* <pre>{@code
39+
*
40+
* Configuration defaultConfiguration = Config.asConfiguration();
2541
*
26-
* List<Integer> codes = Config.list().ofInt("my.codes", 42, 54);
42+
* int port = defaultConfiguration.getInt("port", 8080);
43+
* String host = defaultConfiguration.get("host", "localhost");
2744
*
2845
* }</pre>
2946
*/

0 commit comments

Comments
 (0)