To initialize the configuration using property files, you have to import the ConfigurationManager of Canvas and invoke the initializeFromBundle API to initialize it from the bundle.
Step 1: Import the Configuration Manager class
Code Block |
---|
|
import com.intellectdesign.canvas.config.ConfigurationException;
importcom.intellectdesign.canvas.config.ConfigurationManager; |
Step 2: Trigger the initialize method
Code Block |
---|
|
ConfigurationManager configMgr = ConfigurationManager.getInstance();
configMgr.initializeFromBundle("<PROPERTIES_FILE_NAME>"); |
Assuming that your CT configuration file name is MyImplementation.properties, the syntax to instantiate the bundle is as follows:
Code Block |
---|
|
ConfigurationManager configMgr = ConfigurationManager.getInstance();
configMgr.initializeFromBundle("MyImplementation"); |
That is it! This initializes the Canvas system with the configuration as provided in the bundle MyImplementation.properties loaded from the class path
Info |
---|
Initialization of Canvas Configuration must be done before any user or system requests reach the Canvas application. Hence, it is suggested to include the initialization of the Canvas Configuration as a start up listener or start up Servlet of the application. |
This initialization sequence throws a ConfigurationException if there are any errors while loading the configuration. This can be typically handled to throw an exception to stop your application from loading. The following is a sample code snippet for the exception:
Code Block |
---|
|
try
{
config= ConfigurationManager.getInstance();
config.initializeFromBundle("MyImplementation");
}
catch(ConfigurationException e)
{
LOGGER.error("Configuration system not initialized properly. Cannot service request.", e);
thrownew ServletException("Error while initializing configuration",e);
} |