我在Eclipse创建了一个ZK web application project ,并在Apache Tomcat 9.0.37部署了相同的Apache Tomcat 9.0.37 。 我有一个要读取的属性文件( aws.properties ) - 它位于WEB-INF正下方。 我在加载属性文件 ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我在我的项目中进行了结构更改,我收到了这个错误
项目结构:在此处输入图片描述
平台通知我以下错误:
Step failed
java.lang.NullPointerException: inStream parameter is null
at java.base/java.util.Objects.requireNonNull(Objects.java:233)
at java.base/java.util.Properties.load(Properties.java:407)
at com.crm.framework.config.ConfigReader.ReadProperty(ConfigReader.java:19)
at com.crm.framework.config.ConfigReader.PopulateSettings(ConfigReader.java:11)
at steps.TestInitialize.Initialize(TestInitialize.java:21)
这是我的 ConfigReader,在上面的错误 ConfigReader 中显示:
package com.crm.framework.config;
import com.crm.framework.base.BrowserType;
import java.io.IOException;
import java.util.Properties;
public class ConfigReader {
public static void PopulateSettings() throws IOException {
ConfigReader reader = new ConfigReader();
reader.ReadProperty();
}
private void ReadProperty() throws IOException {
//Create Property Object
Properties p = new Properties();
//Load the property file available in same package
p.load(getClass().getResourceAsStream("GlobalConfig.properties"));
//Get AUTConnection String
Settings.AUTConnectionString = p.getProperty("AUTConnectionString");
//Get Reporting String
Settings.ReportingConnectionString = p.getProperty("ReportingConnectionString");
//Get LogPath
Settings.LogPath = p.getProperty("LogPath");
//Get DriverType
Settings.DriverType = p.getProperty("DriverType");
//Get ExcelSheetPath
Settings.ExcelSheetPath = p.getProperty("ExcelSheetPath");
//Get AUT
Settings.AUT = p.getProperty("AUT");
//Browser Type
Settings.BrowserType = BrowserType.valueOf(p.getProperty("BrowserType"));
}
}
我还附上了 TestInitialize 的代码,该文件包含 @Before 以运行测试用例 TestInitialize:
package steps;
import com.crm.framework.base.DriverContext;
import com.crm.framework.base.FrameworkInitialize;
import com.crm.framework.config.ConfigReader;
import com.crm.framework.config.Settings;
import com.crm.framework.utilities.LogUtil;
import io.cucumber.java.Before;
// import io.cucumber.java.Before;
import java.io.IOException;
public class TestInitialize extends FrameworkInitialize {
@Before
public void Initialize() throws IOException {
//Initialize config
ConfigReader.PopulateSettings();
//Logging
Settings.Logs = new LogUtil();
Settings.Logs.CreateLogFile();
Settings.Logs.Write("Framework initialize");
//Create Test Cycle for Reporting
/*
Pending
*/
Settings.Logs.Write("Test Cycle Created");
InitializeBrowser(Settings.BrowserType);
Settings.Logs.Write("Browser initialize");
DriverContext.Browser.GotoUrl(Settings.AUT);
Settings.Logs.Write("Navigate to URL: " + Settings.AUT);
}
}
这是最可能的罪魁祸首: https://docs.oracle.com/javase/10/docs/api/java/util/Properties.html#getProperty(java.lang.String)
来自 Javadoc:
公共字符串 getProperty(字符串键)
在此属性列表中搜索具有指定键的属性。 如果在该属性列表中未找到该键,则递归地检查默认属性列表及其默认值。 如果未找到该属性,则该方法返回 null 。
属性区分大小写。 确保:
作为故障保护,您可以使用与上述类似的getProperty(key, defaultValue)
,除了在传递给方法的属性键不存在于给定的属性文件。
此外,请确保属性文件的 PATH 是正确的。 如果您不了解资源是如何解决的,那么在从 IDE 和部署环境运行时如何解决文件路径也可能是一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.