我正在准备一个servlet应用程序,并且没有任何属性文件被加载到应用程序中。即使所有属性文件都驻留在同一位置。
代码:
Properties prop = new Properties();
InputStream input = getClass().getClassLoader().getResourceAsStream("ldap.properties");;
try{
logger.debug("Loading Properties File");
//input = new FileInputStream("ldap.properties");
// load a properties file
prop.load(input);
logger.debug("Retry Count is: " + Integer.parseInt(prop.getProperty("retry")));
System.out.println("Retry Count is: " + Integer.parseInt(prop.getProperty("retry")));
logger.debug("downTimeValue is: " + Integer.parseInt(prop.getProperty("downTimeValue")));
retry = Integer.parseInt(prop.getProperty("retry"));
downTimeValue = Integer.parseInt(prop.getProperty("downTimeValue"));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
错误:
[#|2018-01-22T15:34:27.313+0530|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=64;_ThreadName=Thread-2;|log4j:WARN No appenders could be found for logger (com.amdocs.LDAPKit).|#]
[#|2018-01-22T15:34:27.314+0530|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=64;_ThreadName=Thread-2;|log4j:WARN Please initialize the log4j system properly.|#]
[#|2018-01-22T15:34:27.314+0530|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=64;_ThreadName=Thread-2;|log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.|#]
[#|2018-01-22T16:02:37.033+0530|WARNING|oracle-glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=67;_ThreadName=Thread-2;|StandardWrapperValve[com.amdocs.LDAPKit]: PWC1406: Servlet.service() for servlet com.amdocs.LDAPKit threw exception
java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:434)
at java.util.Properties.load0(Properties.java:353)
at java.util.Properties.load(Properties.java:341)
at com.amdocs.LDAPKit.doPost(LDAPKit.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)