Package io.sysr.springcontext.env
Class EnvContextLoader
java.lang.Object
io.sysr.springcontext.env.EnvContextLoader
The
EnvContextLoader class is responsible for loading environment
variables from .env files or an env.properties file
into a properties map.
It handles variable resolution, including nested variables, validates
variable names and detects circular dependencies.
Example usage:
// Create an instance of the loader
EnvContextLoader loader = new EnvContextLoader();
// Load environment variables
loader.load();
// Retrieve the loaded properties
Properties properties = loader.getLoadedProperties();
// Access a property
String dbUrl = properties.getProperty("DATABASE_URL");
Note: Ensure that the dotenv properties configuration file (env.properties) is placed in the resources foler. This only applies if you have the .env file that contains the environment declarions is placed in a custom location.
- Since:
- 2024
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the loaded properties as aPropertiesobject.voidload()Initiates the loading process of environment variables.
-
Constructor Details
-
EnvContextLoader
public EnvContextLoader()Constructs a newEnvContextLoaderinstance.
-
-
Method Details
-
getLoadedProperties
Retrieves the loaded properties as aPropertiesobject.- Returns:
- The
Propertiesobject containing all loaded and resolved environment variables.
-
load
public void load()Initiates the loading process of environment variables.It attempts to load variables from a user-provided file which is specified in the
env.propertiesfile or from.envfiles in the default root directory.- Throws:
EnvContextLoaderException- if there is any error during the loading process.
-