P
- the type of the parent builder (when calling Parent.and()
method)public interface EnvironmentBuilder<P> extends Parent<P>, Builder<PropertyResolver>
The user can use either system properties or custom properties or properties loaded from a file. The user can also mix them. For example, he can use system properties and custom properties.
The user can also configure how conversions are applied to properties (converting a string that comes from properties into an integer for example).
Finally, the user can also use a custom PropertyResolver
(the
property resolver is the abstraction used to read properties).
Built PropertyResolver
will then be used in almost every builder to
evaluate property keys (in the form of "${custom.property}").
Modifier and Type | Method and Description |
---|---|
ConverterBuilder<EnvironmentBuilder<P>> |
converter()
Configure how conversions are applied on properties.
|
EnvironmentBuilder<P> |
override()
Overrides any previously defined properties.
|
PropertiesBuilder<EnvironmentBuilder<P>> |
properties()
Provide custom properties using fluent API.
|
PropertiesBuilder<EnvironmentBuilder<P>> |
properties(int priority)
Provide custom properties using fluent API.
|
EnvironmentBuilder<P> |
properties(Properties properties)
Provide custom properties.
|
EnvironmentBuilder<P> |
properties(Properties properties,
int priority)
Provide custom properties.
|
EnvironmentBuilder<P> |
properties(String path)
Load a property file using its path.
|
EnvironmentBuilder<P> |
properties(String path,
int priority)
Load a property file using its path.
|
EnvironmentBuilder<P> |
resolver(PropertyResolver resolver)
Defined a custom
PropertyResolver instead of the default one. |
EnvironmentBuilder<P> |
systemProperties()
Use system properties.
|
EnvironmentBuilder<P> |
systemProperties(int priority)
Use system properties.
|
EnvironmentBuilder<P> override()
.properties("foo.properties")
.properties(myProperties)
.systemProperties()
.override()
.properties()
.set("foo", "bar")
The three first lines won't be taken into account. Only the properties
defined after are used.EnvironmentBuilder<P> properties(String path)
classpath:conf/myprops.properties
: loads a file named
"myprops.properties" in the classpathfile:/home/foo/myprops.properties
: loads a file named
"myprops.properties" from the file systemconf/myprops.properties
: loads a file named
"myprops.properties" in the classpathThe path may contain a ? character. It means that the path is optional and it doesn't fail if the file doesn't exist.
The priority of the registered properties depends on if the file is loaded from the classpath or from the filesystem. The priority is used to order all registered properties. Registered properties with higher priorities are used first. It means that when requesting for a property value the highest priority is requested first to get the value if it exists. If it doesn't exist, the second is requested and so on. If several properties are registered with the same priority, then the registration order is used.
The default priorities are:
Properties
object = 80000properties()
fluent API =
80000path
- the path to the property fileEnvironmentBuilder<P> properties(String path, int priority)
classpath:conf/myprops.properties
: loads a file named
"myprops.properties" in the classpathfile:/home/foo/myprops.properties
: loads a file named
"myprops.properties" from the file systemconf/myprops.properties
: loads a file named
"myprops.properties" in the classpathThe path may contain a ? character. It means that the path is optional and it doesn't fail if the file doesn't exist.
Indicates the priority of the registered properties. The priority is used to order all registered properties. Registered properties with higher priorities are used first. It means that when requesting for a property value the highest priority is requested first to get the value if it exists. If it doesn't exist, the second is requested and so on. If several properties are registered with the same priority, then the registration order is used.
path
- the path to the property filepriority
- the priority of the propertiesEnvironmentBuilder<P> properties(Properties properties)
The priority of the registered properties is 80000. The priority is used to order all registered properties. Registered properties with higher priorities are used first. It means that when requesting for a property value the highest priority is requested first to get the value if it exists. If it doesn't exist, the second is requested and so on. If several properties are registered with the same priority, then the registration order is used.
The default priorities are:
Properties
object = 80000properties()
fluent API =
80000properties
- the custom propertiesEnvironmentBuilder<P> properties(Properties properties, int priority)
Indicates the priority of the registered properties. The priority is used to order all registered properties. Registered properties with higher priorities are used first. It means that when requesting for a property value the highest priority is requested first to get the value if it exists. If it doesn't exist, the second is requested and so on. If several properties are registered with the same priority, then the registration order is used.
properties
- the custom propertiespriority
- the priority of the propertiesPropertiesBuilder<EnvironmentBuilder<P>> properties()
The priority of the registered properties is 80000. The priority is used to order all registered properties. Registered properties with higher priorities are used first. It means that when requesting for a property value the highest priority is requested first to get the value if it exists. If it doesn't exist, the second is requested and so on. If several properties are registered with the same priority, then the registration order is used.
The default priorities are:
Properties
object = 80000properties()
fluent API =
80000PropertiesBuilder<EnvironmentBuilder<P>> properties(int priority)
Indicates the priority of the registered properties. The priority is used to order all registered properties. Registered properties with higher priorities are used first. It means that when requesting for a property value the highest priority is requested first to get the value if it exists. If it doesn't exist, the second is requested and so on. If several properties are registered with the same priority, then the registration order is used.
priority
- the priority of the propertiesEnvironmentBuilder<P> systemProperties()
The priority of the registered properties is 100000. The priority is used to order all registered properties. Registered properties with higher priorities are used first. It means that when requesting for a property value the highest priority is requested first to get the value if it exists. If it doesn't exist, the second is requested and so on. If several properties are registered with the same priority, then the registration order is used.
The default priorities are:
Properties
object = 80000properties()
fluent API =
80000EnvironmentBuilder<P> systemProperties(int priority)
Indicates the priority of the registered properties. The priority is used to order all registered properties. Registered properties with higher priorities are used first. It means that when requesting for a property value the highest priority is requested first to get the value if it exists. If it doesn't exist, the second is requested and so on. If several properties are registered with the same priority, then the registration order is used.
priority
- the priority of the propertiesConverterBuilder<EnvironmentBuilder<P>> converter()
Properties are like a map with a string key and often a string value. In an application, you need to work with real objects (not always strings). The converter will be used to transform a string value that comes from properties into a real object.
Using the ConverterBuilder
is useful to register custom
converters.
EnvironmentBuilder<P> resolver(PropertyResolver resolver)
PropertyResolver
instead of the default one.
Using a custom PropertyResolver
may be useful when default
implementation doesn't fit your needs. For example, when using Spring,
Ogham will automatically register a property resolver that uses Spring
Environment concept.
resolver
- the custom resolverCopyright © 2021. All rights reserved.