I have a scenario, I am trying to implement error code mechanism in my application.this is the approach what I am following currently.
Properties prop = new Properties();
InputStream input = null;
try {
String filename = "ErrorCode.properties";
input = getClass().getClassLoader().getResourceAsStream(filename);
if (input == null) {
log.debug("Sorry, unable to find " + filename);
return null;
}
prop.load(input);
Enumeration<?> e = prop.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = prop.getProperty(key);
log.debug("Key : " + key + ", Value : " + value);
}
But I need error code in lots of different classes and I don't want to write the above code all the time in different classes.
Is there any other way it initialize the property file once and use it any where in the class.
How do I achieve this?
What are different possible ways to achieve this?
I am using spring, is there any way to achieve this in spring?
I am open for any other mechanism instead of property file.