First, there are a lot of solutions out there and I have already read a lot of them. But for some reason I don't get it working.
I am trying to outsource my config data for my webapp, so that I can cnange it after deployment.
That is my properties service:
public class PropertiesService {
Properties properties;
public PropertiesService() {
try {
properties = new Properties();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream stream = classLoader.getResourceAsStream("META-INF/config.properties");
properties.load(stream);
} catch (Exception e) {
e.printStackTrace();
}
}
public String getHost(){
return properties.getProperty("server_host");
}
public String getServerName(){
return properties.getProperty("server_naming");
}
}
After debugging I noticed that the variable stream remains null! But I don't know why -.-
Need help :-)
here the error log:
java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:418)
at java.util.Properties.load0(Properties.java:337)
at java.util.Properties.load(Properties.java:325)
Update
I do the following now:
properties.load(this.getClass().getResourceStream("/config/config.properties"));
And I still get a nullPointerException
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…