我需要使用设置一些全局变量,这些变量将被几个类使用。从属性文件设置静态变量java
我无法从属性文件中分配静态变量。
我想调用变量是这样的:String url = WebdriverConfiguration.getBaseUrl();
public class WebDriverConfiguration
{
private static Properties testProperties;
private static String instaceUrl;
testProperties = loadProperties();
public static final String DEFAULT_BASEURL = testProperties.getProperty("confluence.base.url","");
private static final int DEFAULT_HTTP_PORT = 8080;
private static final String DEFAULT_CONTEXT_PATH = "/";
public static final String TEST_SPACE_KEY = "SMOKE";
public static final String TEST_PAGE = "XXX";
private static final String BASE_URL = System.getProperty("baseurl", DEFAULT_BASEURL);
public static String getBaseUrl()
{
return BASE_URL;
}
private Properties loadProperties() throws IOException
{
InputStream testPropertiesInput = getClass().getClassLoader().getResourceAsStream("webtester.properties");
Properties testProperties = new Properties();
if (null != testPropertiesInput)
{
try
{
testProperties.load(testPropertiesInput);
}
finally
{
IOUtils.closeQuietly(testPropertiesInput);
}
}
return testProperties;
}
}
问题是什么? –
想从该属性文件分配静态变量,看看有一些静态变量,我想从属性中获得一些。加载是好的,只是无法从另一个类实例化它。 – user979587