Package org.kohsuke.stapler.config
Class ConfigurationLoader
java.lang.Object
org.kohsuke.stapler.config.ConfigurationLoader
Provides a type-safe access to the configuration of the application.
Often web applications need to load configuration from outside. T
Typical usage would be MyConfig config=ConfigurationLoad.from(...).as(MyConfig.class)
where the MyConfig
interface defines a bunch of methods named after
the property name:
interface MyConfig { File rootDir(); int retryCount(); String domainName(); ... }
Method calls translate to respective property lookup. For example, config.rootDir()
would
be equivalent to new File(properties.get("rootDir"))
.
The method name can include common prefixes, such as "get", "is", and "has", and those portions
will be excluded from the property name. Thus the rootDir()
could have been named getRootDir()
.
- Author:
- Kohsuke Kawaguchi
-
Method Summary
Modifier and TypeMethodDescription<T> T
Creates a type-safe proxy that reads from the source specified by one of the fromXyz methods.static ConfigurationLoader
Loads the configuration from the specified property file.static ConfigurationLoader
static ConfigurationLoader
from
(Properties props) Loads the configuration from the specifiedProperties
object.static ConfigurationLoader
CreatesConfigurationLoader
that uses environment variables as the source.static ConfigurationLoader
CreatesConfigurationLoader
that uses all the system properties as the source.
-
Method Details
-
from
Loads the configuration from the specified property file.- Throws:
IOException
-
from
Loads the configuration from the specifiedProperties
object.- Throws:
IOException
-
from
- Throws:
IOException
-
fromSystemProperties
CreatesConfigurationLoader
that uses all the system properties as the source.- Throws:
IOException
-
fromEnvironmentVariables
CreatesConfigurationLoader
that uses environment variables as the source. Since environment variables are often by convention all caps, while system properties and other properties tend to be camel cased, this method creates a case-insensitive configuration (that allows retrievals by both "path" and "PATH" to fill this gap.- Throws:
IOException
-
as
Creates a type-safe proxy that reads from the source specified by one of the fromXyz methods.
-