public class StdPropFileOnClasspathLoader extends PropFileOnClasspathLoader implements StandardLoader
.property file on the
classpath. By default, this loader will look for a file named
andhow.properties at the root of the classpath.
andhow.properties
at the root of the classpath via the StdPropFileOnClasspathLoader.
andhow.properties from the root of the classpath
java.util.Properties,
which silently ignores duplicate property entries
(i.e., the same key appearing multiple times). When there are duplicate
property keys in a properties file, only the last assigned value is used.
Full details on how Java parses properties files can be found in the
properties file specification.
Configuring the name or classpath of the properties file can be used to
enable different configuration profiles based on the environment.
For instance, a system property could specify that /test.properties
be used on a test server and /production.properties on a production
server. An example of configuring the property file path:
import org.yarnandtail.andhow.*;
import org.yarnandtail.andhow.property.StrProp;
public class UsePropertyFileOnClasspath implements AndHowInit {
public static final StrProp MY_CLASSPATH = StrProp.builder()
.desc("Path to a properties file on the classpath. "
+ "If the file is not present, it is not considered an error.").build();
@Override
public AndHowConfiguration getConfiguration() {
return StdConfig.instance()
.setClasspathPropFilePath(MY_CLASSPATH);
}
}
The code above adds the property MY_CLASSPATH
(the name is arbitrary) which is used to configure the
StdPropFileOnClasspathLoader with a custom property file location.
When AndHow initializes, the StdPropFileOnClasspathLoader checks to
see if a value has been loaded for MY_CLASSPATH by any prior loader.
If a value is present, the loader tries to load from the configured classpath.
If no value is configured, the default classpath is assumed.
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().| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_PROP_FILE |
missingFileAProblem, pathProp, pathStr, unknownPropertyAProblem| Constructor and Description |
|---|
StdPropFileOnClasspathLoader()
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 |
|---|---|
protected String |
getEffectivePath(ValidatedValuesWithContext existingValues)
Utility method to simplify finding the effective path.
|
getSpecificLoadDescription, load, loadgetConfigSamplePrinter, getInstanceConfig, getLoaderDialect, getLoaderType, isMissingFileAProblem, isTrimmingRequiredForStringValues, isUnknownPropertyAProblem, loadInputStreamToProps, setFilePath, setFilePath, setMissingFileAProblem, setUnknownPropertyAProblemattemptToAdd, attemptToAdd, createValue, findDuplicateProperty, getClassConfig, releaseResourcesclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetClassConfig, getConfigSamplePrinter, getInstanceConfig, getLoaderDialect, getLoaderType, getSpecificLoadDescription, isTrimmingRequiredForStringValues, load, releaseResourcespublic static final String DEFAULT_PROP_FILE
public StdPropFileOnClasspathLoader()
protected String getEffectivePath(ValidatedValuesWithContext existingValues)
PropFileBaseLoadergetEffectivePath in class PropFileBaseLoaderCopyright © 2021. All rights reserved.