Class ConfigLoader
java.lang.Object
com.ns.tcpframework.ConfigLoader
Utility class for loading server configuration from YAML files.
This class provides functionality to load environment-specific server configurations from YAML files. It supports loading from both external file system paths and classpath resources, with priority given to external configurations.
Configuration file location:
- External:
config/config.{environment}.yaml(file system) - Classpath:
config/config.{environment}.yaml(resources)
The loader uses Jackson's YAML parser to deserialize configuration files into
structured ServerConfig objects, including virtual host configurations
and route mappings.
Example usage:
ServerConfig config = ConfigLoader.load("production");
// Loads from config/config.production.yaml
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ServerConfigLoads server configuration for the specified environment.
-
Constructor Details
-
ConfigLoader
public ConfigLoader()
-
-
Method Details
-
load
Loads server configuration for the specified environment.This method attempts to load configuration in the following order:
- External file system path:
config/config.{environment}.yaml - Classpath resource:
config/config.{environment}.yaml
The configuration file should contain:
- environment: The environment name (e.g., "development", "production")
- port: The server port number
- logLevel: The logging level (DEBUG, INFO, WARN, ERROR, FATAL)
- defaultHost: The name of the default virtual host
- hosts: A map of virtual host configurations with routes
- Parameters:
environment- The environment name used to locate the configuration file (e.g., "development", "staging", "production").- Returns:
- A
ServerConfigobject containing all parsed configuration data. - Throws:
IOException- If an error occurs while reading or parsing the configuration file.IllegalArgumentException- If the configuration file cannot be found in either the file system or classpath.RuntimeException- If an error occurs during handler initialization or route registration.
- External file system path:
-