Back Forum Reply New

Reading properties file

In my java app there is a code which reads the properties file from src/main/resources folder. Code:
@Component(quot;mailerPropertiesquot;)
public class MailerProperties {

private static Properties properties;

public MailerProperties() {
properties = new Properties();
InputStream inStream;
try {
inStream = (new ClassPathResource(quot;mailer.propertiesquot;)).getInputStream();
properties.load(inStream);
} catch (IOException e) {
e.printStackTrace();
}
}

public String getValue(String key) {
return properties.getProperty(key);
}}
Now I need to create a jar file and also remove the properties file from src/main/resources folder and place it outside the jar file(in the same location as jar file) so that data inside it can be changed easily in future.

Question: Currently it uses ClassPathResource(quot;mailer.propertiesquot;) to read the prop file. What change I need to make to read it from outside the jar file

blog/2009/...s-with-spring/

2008/04/2...s-with-spring/
¥
Back Forum Reply New