Class VirtualEnvironmentConfiguration

java.lang.Object
com.dianxin.tori.base.env.VirtualEnvironmentConfiguration

@NullMarked public final class VirtualEnvironmentConfiguration extends Object
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 Type
    Method
    Description
    static @Nullable String
    get(String key)
    Retrieves the environment variable value linked with the specified key.
    static String
    getOrDefault(String key, String defaultValue)
    Retrieves the environment variable value associated with the specified key, returning the fallback value if the key is missing.
    static String
    Retrieves the environment variable value linked with the specified key, throwing an exception if the key is not present.
    static String
    Retrieves the environment variable value linked with the specified key, throwing a custom exceptions wrapper if the key is missing.
    static void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • wakeup

      public static void wakeup()
    • get

      public static @Nullable String get(String key)
      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 null if the key is not defined anywhere
    • getOrDefault

      public static String getOrDefault(String key, String defaultValue)
      Retrieves the environment variable value associated with the specified key, returning the fallback value if the key is missing.
      Parameters:
      key - the configuration key name
      defaultValue - the fallback value to return if no entry is found
      Returns:
      the configuration value, or the default value if unresolved
    • getOrThrow

      public static String getOrThrow(String key)
      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

      public static String getOrThrow(String key, Throwable th) throws Throwable
      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 name
      th - the custom exception instance to be thrown
      Returns:
      the resolved configuration value string
      Throws:
      Throwable - the customized exception provided as a parameter