@Override
  public void contextDestroyed(ServletContextEvent sce) {
    try {
      OpenFlameDataSource bean = OpenFlameSpringContext.getBean(OpenFlameDataSource.class);
      bean.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    try {
      Scheduler scheduler = OpenFlameSpringContext.getBean(Scheduler.class);
      scheduler.shutdown();
    } catch (SchedulerException e) {
      e.printStackTrace();
    }
    Env.clean();
    JAXBContextCache.clearCaches();
    ClassFactory.cleanCache();
    CachedIntrospectionResults.clearClassLoader(getClass().getClassLoader());

    super.contextDestroyed(sce);
  }
  @Override
  public void contextInitialized(ServletContextEvent sce) {
    File app = Env.getDefaultEnvFile();
    File keyStore = InstallUtils.getKeyStore();

    Map<String, String> propertiesMap = KeyUtils.getMapProperties(app, keyStore);
    ConfigContainer.putAll(propertiesMap);

    File xmlProp = InstallUtils.getXmlEnv();
    if (!ConfigContainer.isAppInstalled() && xmlProp.exists()) {
      Map<String, String> settings = EnvironmentsUtils.convertFromXml(xmlProp);
      ConfigContainer.putAll(settings);
    }

    File propFile = InstallUtils.getPropEnv();
    if (!ConfigContainer.isAppInstalled() && propFile.exists()) {
      ConfigContainer.putAll(MiscUtils.getProperties(propFile));
    }

    if (!xmlProp.exists()) {
      if (!OpenFlameConfig.DOMAIN_URL.exist())
        OpenFlameConfig.DOMAIN_URL.setValue(TomcatUtils.getCatalinaHost(sce));
      if (!OpenFlameConfig.PORT.exist())
        OpenFlameConfig.PORT.setValue(TomcatUtils.getCatalinaPort(sce).toString());
      if (!OpenFlameConfig.CONTEXT_URL.exist())
        OpenFlameConfig.CONTEXT_URL.setValue(TomcatUtils.getCatalinaContext(sce));
    }

    String domainUrl = OpenFlameConfig.DOMAIN_URL.getValue();
    String port = OpenFlameConfig.PORT.getValue();
    String contextUrl = OpenFlameConfig.CONTEXT_URL.getValue();
    if (domainUrl != null && port != null && contextUrl != null) {
      Env.FIREJACK_URL.setValue(WebUtils.getNormalizedUrl(domainUrl, port, contextUrl));
    }

    ConfigContainer.setHost(TomcatUtils.getCatalinaHost(sce));
    ConfigContainer.setPort(TomcatUtils.getCatalinaPort(sce));

    super.contextInitialized(sce);
  }