public class StdSysPropLoader extends BaseMapLoader implements StandardLoader
Property value loading is based on a 'first win' strategy, so the first loader to find a non-null value for a property sets the value.
An application might receive all or some of its configuration from Java system properties that are set when the JVM starts up. Java system properties can be set in a startup script, which could be customized for each environment. This provides a relatively easy way for deployment automation or system administrators to control application configuration values across many servers.
QuotedSpacePreservingTrimmer.
Non-String values are always trimmed to null.
This loader loads properties from the values it finds in java.lang.System.getProperties()
at the time AndHow is initialized. Over the lifecycle of the JVM, the values of system properties
can change so they may not reflect the values AndHow has loaded. However,
once loaded, AndHow property values never change. It is also possible for
application code to add to or modify system properties after the JVM starts up and before
AndHow initializes, potentially resulting in a AndHow's configuration not matching the values set
in a JVM startup script.
For FlgProp properties (true/false flags), the StdSysPropLoader
will set the Property's value to true if a matching environment variable is found,
even if the value of the property is empty. System properties can be cleared via
java.lang.System.clearProperty(name), which is how a flag value could
be unset prior to AndHow loading.
Passing system properties on command line looks like this:
java -Dfull.name.of.MY_PROPERTY=someValue -jar MyJarName.jar
StandardLoader's, this loader is intended to be auto-created
by AndHow. The set of standard loaders and their order can bet set
via the AndHowConfiguration.setStandardLoaders() methods.
Other loaders which don't implement the StandardLoader interface can
be inserted into the load order via the
AndHowConfiguration.insertLoaderBefore/After().unknownPropertyAProblem| Constructor and Description |
|---|
StdSysPropLoader()
There is no reason to use the constructor in production application code
because AndHow creates a single instance on demand at runtime.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getLoaderType()
The type of the loader, such as JNDI, PropertyFile, SystemProperty,
etc..
|
String |
getSpecificLoadDescription()
For this particular load, where was info loaded from?
This may vary from run to run based on config params.
|
boolean |
isTrimmingRequiredForStringValues()
If true, values for string properties are trimmed by the Trimmer of
the property they are associated with.
|
LoaderValues |
load(PropertyConfigurationInternal runtimeDef,
LoaderEnvironment environment,
ValidatedValuesWithContext existingValues)
Builds up a list of LoaderValues by loading property values from a configuration source.
|
getLoaderDialect, isFlaggable, isUnknownPropertyAProblem, load, setUnknownPropertyAProblemattemptToAdd, attemptToAdd, attemptToAdd, attemptToAddIfNotDuplicate, createValue, findDuplicateProperty, getClassConfig, getConfigSamplePrinter, getInstanceConfig, mapNametoProperty, releaseResourcesclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetClassConfig, getConfigSamplePrinter, getInstanceConfig, getLoaderDialect, isFlaggable, releaseResourcespublic StdSysPropLoader()
public LoaderValues load(PropertyConfigurationInternal runtimeDef, LoaderEnvironment environment, ValidatedValuesWithContext existingValues)
LoaderLoaders find and load values and associate them with the correct Property. If there is a problem while doing that, they register one or more LoaderProblems in the returned LoaderValues.
Validation of Property values is not Loader's responsibility and will be handled outside this method.
load in interface LoaderruntimeDef - The definition of all known Properties and naming metadata.environment - The environment (System Props, Env vars, fixed values) as
known to the Loader.existingValues - The values already set by prior loaders, which may configure
the behavior of this loader.public String getSpecificLoadDescription()
LoadergetSpecificLoadDescription in interface LoadergetSpecificLoadDescription in class BaseMapLoaderpublic boolean isTrimmingRequiredForStringValues()
LoaderisTrimmingRequiredForStringValues in interface LoaderisTrimmingRequiredForStringValues in class BaseMapLoaderpublic String getLoaderType()
LoadergetLoaderType in interface LoadergetLoaderType in class BaseMapLoaderCopyright © 2022. All rights reserved.