Package com.tnsai.config
Class EnvLoader
java.lang.Object
com.tnsai.config.EnvLoader
Utility class for loading environment variables from .env file.
Automatically loads .env file once on first access.
Searches for .env file in:
- Current directory
- Parent directory (for Maven multi-module projects)
- Two levels up (for deeply nested structures)
Once loaded, environment variables are accessible via:
System.getProperty(String)- System properties (preferred)System.getenv(String)- Original environment variables
-
Constructor Details
-
EnvLoader
public EnvLoader()
-
-
Method Details
-
ensureLoaded
public static void ensureLoaded()Ensure .env file is loaded. Safe to call multiple times - loads only once. -
get
Get environment variable value. Checks System properties first, then environment variables.- Parameters:
key- Variable name- Returns:
- Value or null if not found
-
get
Get environment variable value with default.- Parameters:
key- Variable namedefaultValue- Default value if not found- Returns:
- Value or default
-
has
Check if environment variable is set and non-empty.- Parameters:
key- Variable name- Returns:
- true if set and non-empty
-