Package com.dianxin.tori.base.env
Class VirtualEnvironmentConfiguration
java.lang.Object
com.dianxin.tori.base.env.VirtualEnvironmentConfiguration
Utility class for environment configuration management.
Loads configuration variables from both native system environment variables
and local environment files (e.g.,
.env) via the Dotenv library.
System environment variables always take precedence over properties defined in the local file.
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable StringRetrieves the environment variable value linked with the specified key.static StringgetOrDefault(String key, String defaultValue) Retrieves the environment variable value associated with the specified key, returning the fallback value if the key is missing.static StringgetOrThrow(String key) Retrieves the environment variable value linked with the specified key, throwing an exception if the key is not present.static StringgetOrThrow(String key, Throwable th) Retrieves the environment variable value linked with the specified key, throwing a custom exceptions wrapper if the key is missing.static voidwakeup()
-
Method Details
-
wakeup
public static void wakeup() -
get
Retrieves the environment variable value linked with the specified key. Looks up system environment variables first before checking the local dotenv context.- Parameters:
key- the configuration key name- Returns:
- the configuration value string, or
nullif the key is not defined anywhere
-
getOrDefault
Retrieves the environment variable value associated with the specified key, returning the fallback value if the key is missing.- Parameters:
key- the configuration key namedefaultValue- the fallback value to return if no entry is found- Returns:
- the configuration value, or the default value if unresolved
-
getOrThrow
Retrieves the environment variable value linked with the specified key, throwing an exception if the key is not present.- Parameters:
key- the configuration key name- Returns:
- the resolved configuration value string
- Throws:
RuntimeException- if the key cannot be found in the current environment context
-
getOrThrow
Retrieves the environment variable value linked with the specified key, throwing a custom exceptions wrapper if the key is missing.- Parameters:
key- the configuration key nameth- the custom exception instance to be thrown- Returns:
- the resolved configuration value string
- Throws:
Throwable- the customized exception provided as a parameter
-