@Test public void testLoadCascadedProperties() throws Exception { SimpleDeploymentContext context = new SimpleDeploymentContext(); context.setDeploymentEnvironment("test"); context.setDeploymentRegion("us-east-1"); ConfigurationManager.setDeploymentContext(context); ConfigurationManager.loadCascadedPropertiesFromResources("test"); assertEquals("9", ConfigurationManager.getConfigInstance().getProperty("com.netflix.config.samples.SampleApp.SampleBean.numSeeds")); assertEquals("1", ConfigurationManager.getConfigInstance().getProperty("cascaded.property")); ConfigurationManager.loadAppOverrideProperties("override"); assertEquals("200", ConfigurationManager.getConfigInstance().getProperty("cascaded.property")); }
private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; if (instance == null) { instance = getConfigInstance(); } ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = getDeploymentContext().getDeploymentEnvironment(); if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; }
ConfigurationManager { private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; if (instance == null) { instance = getConfigInstance(); } ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = getDeploymentContext().getDeploymentEnvironment(); if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; } }
ConfigurationManager { private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; if (instance == null) { instance = getConfigInstance(); } ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = getDeploymentContext().getDeploymentEnvironment(); if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; }  }
ConfigurationManager { private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; if (instance == null) { instance = getConfigInstance(); } ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = getDeploymentContext().getDeploymentEnvironment(); if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; }  static StackTraceElement[] getStaticInitializationSource(); static Set<String> getLoadedPropertiesURLs(); static synchronized void install(AbstractConfiguration config); static synchronized boolean isConfigurationInstalled(); static AbstractConfiguration getConfigInstance(); static void loadPropertiesFromResources(String path); static void loadCascadedPropertiesFromResources(String configName); static void loadAppOverrideProperties(String appConfigName); static void loadPropertiesFromConfiguration(AbstractConfiguration config); static void loadProperties(Properties properties); static void setDeploymentContext(DeploymentContext context); static DeploymentContext getDeploymentContext(); static AbstractConfiguration getConfigFromPropertiesFile(URL startingUrl); static Properties getPropertiesFromFile(URL startingUrl); }
ConfigurationManager { private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; if (instance == null) { instance = getConfigInstance(); } ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = getDeploymentContext().getDeploymentEnvironment(); if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; }  static StackTraceElement[] getStaticInitializationSource(); static Set<String> getLoadedPropertiesURLs(); static synchronized void install(AbstractConfiguration config); static synchronized boolean isConfigurationInstalled(); static AbstractConfiguration getConfigInstance(); static void loadPropertiesFromResources(String path); static void loadCascadedPropertiesFromResources(String configName); static void loadAppOverrideProperties(String appConfigName); static void loadPropertiesFromConfiguration(AbstractConfiguration config); static void loadProperties(Properties properties); static void setDeploymentContext(DeploymentContext context); static DeploymentContext getDeploymentContext(); static AbstractConfiguration getConfigFromPropertiesFile(URL startingUrl); static Properties getPropertiesFromFile(URL startingUrl); static final String PROP_NEXT_LOAD; static final String URL_CONFIG_NAME; static final String SYS_CONFIG_NAME; static final String ENV_CONFIG_NAME; static final String DISABLE_DEFAULT_ENV_CONFIG; static final String DISABLE_DEFAULT_SYS_CONFIG; static final String APPLICATION_PROPERTIES; }