/** * This is a convenience method to load a resource as a stream. * <p/> * The algorithm used to find the resource is given in getResource() * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ private static InputStream getResourceAsStream(String resourceName, Class callingClass) { URL url = getResource(resourceName, callingClass); try { return url != null ? url.openStream() : null; } catch (IOException e) { return null; } }
private static void loadPropertiesFromClasspath(String propertiesName, Properties properties) { try { properties.load(getResourceAsStream(propertiesName, PropertiesLoader.class)); } catch (Exception e) { log.error("Error loading " + propertiesName + " properties from classpath.", e); } }
loadPropertiesFromClasspath(propertiesName, properties); loadPropertiesFromClasspath(propertiesName, properties);