/** * Returns {@code true} if a property named {@code spring.cloud.appId} is present in any of the property sources. * On the first call, attempts to load properties from a file specified in {@code spring.cloud.propertiesFile}. */ @Override public boolean isInMatchingCloud() { if (fileProperties == null) readFileProperties(); String appId = findProperty(APP_ID_PROPERTY); if (appId == null) logger.info("the property " + APP_ID_PROPERTY + " was not found in the system properties or configuration file"); return appId != null; }
/** * Checks for the presence of a supplied or system property named {@code spring.cloud.propertiesFile}. If the property * is present, load its contents into {@link #fileProperties}. If there's a problem, log but continue. */ private void readFileProperties() { fileProperties = new Properties(); logger.fine("looking for a properties file"); // will search system properties and the classpath File propertiesFile = new PropertiesFileResolver(env).findCloudPropertiesFile(); if (propertiesFile == null) { logger.info("not loading service definitions from a properties file"); return; } if (!fileExists(propertiesFile)) { logger.info("properties file " + propertiesFile + " does not exist; probably running in a real cloud"); return; } logger.info("loading service definitions from properties file " + propertiesFile); try { InputStream fis = openFile(propertiesFile); fileProperties.load(fis); fis.close(); } catch (IOException e) { logger.log(Level.SEVERE, "exception while loading properties from file " + propertiesFile, e); return; } logger.info("properties loaded successfully"); }
@Override public ApplicationInstanceInfo getApplicationInstanceInfo() { return new BasicApplicationInstanceInfo(UUID.randomUUID().toString(), findProperty(APP_ID_PROPERTY), Collections.<String, Object>emptyMap()); }
/** * Look for a specific property in the config file or the system properties. * * @param key the property to look for * @return the preferred value for the key, or {@code null} if the key is not found */ private String findProperty(String key) { String value = fileProperties.getProperty(key); try { value = env.getSystemProperty(key, value); } catch (SecurityException e) { logSystemReadException(key, e); } return value; }
/** * Checks for the presence of a supplied or system property named {@code spring.cloud.propertiesFile}. If the property * is present, load its contents into {@link #fileProperties}. If there's a problem, log but continue. */ private void readFileProperties() { fileProperties = new Properties(); logger.fine("looking for a properties file"); // will search system properties and the classpath File propertiesFile = new PropertiesFileResolver(env).findCloudPropertiesFile(); if (propertiesFile == null) { logger.info("not loading service definitions from a properties file"); return; } if (!fileExists(propertiesFile)) { logger.info("properties file " + propertiesFile + " does not exist; probably running in a real cloud"); return; } logger.info("loading service definitions from properties file " + propertiesFile); try { InputStream fis = openFile(propertiesFile); fileProperties.load(fis); fis.close(); } catch (IOException e) { logger.log(Level.SEVERE, "exception while loading properties from file " + propertiesFile, e); return; } logger.info("properties loaded successfully"); }
@Override public ApplicationInstanceInfo getApplicationInstanceInfo() { return new BasicApplicationInstanceInfo(UUID.randomUUID().toString(), findProperty(APP_ID_PROPERTY), Collections.<String, Object>emptyMap()); }
/** * Look for a specific property in the config file or the system properties. * * @param key the property to look for * @return the preferred value for the key, or {@code null} if the key is not found */ private String findProperty(String key) { String value = fileProperties.getProperty(key); try { value = env.getSystemProperty(key, value); } catch (SecurityException e) { logSystemReadException(key, e); } return value; }
/** * Returns {@code true} if a property named {@code spring.cloud.appId} is present in any of the property sources. * On the first call, attempts to load properties from a file specified in {@code spring.cloud.propertiesFile}. */ @Override public boolean isInMatchingCloud() { if (fileProperties == null) readFileProperties(); String appId = findProperty(APP_ID_PROPERTY); if (appId == null) logger.info("the property " + APP_ID_PROPERTY + " was not found in the system properties or configuration file"); return appId != null; }