|
18 | 18 | * Provides application Configuration based on loading properties and yaml files |
19 | 19 | * as well as plugins that supply properties (like dynamic configuration loaded from a db). |
20 | 20 | * <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> |
21 | 38 | * The application can register onChange listeners to handle changes to configuration |
22 | 39 | * properties at runtime. Plugins or code can dynamically load and change properties and |
23 | 40 | * this can fire any registered callback handlers. |
24 | | - * </p> |
25 | 41 | * |
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> |
27 | 50 | * <pre>{@code |
28 | 51 | * |
29 | 52 | * int port = Config.getInt("app.port", 8090); |
|
33 | 56 | * List<Integer> codes = Config.list().ofInt("my.codes", 42, 54); |
34 | 57 | * |
35 | 58 | * }</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> |
36 | 80 | */ |
37 | 81 | @NonNullApi |
38 | 82 | public class Config { |
|
0 commit comments