我有一个使用 SSL 连接到 Web 服务的应用程序。 在与 Web 服务器建立连接的类的静态中,我有这个:
static {
URL url = null;
try {
URL baseUrl;
baseUrl = ar.com.cfa.xmlns.wsevaluartdm.WSEvaluarTDM.class.getResource(".");
url = new URL(baseUrl, "https://www.site.com/WS.asmx?WSDL");
} catch (MalformedURLException e) {
logger.warning("Failed to create URL for the wsdl Location: 'https://www.site.com/WS.asmx?WSDL', retrying as a local file");
logger.warning(e.getMessage());
}
WSEVALUARTDM_WSDL_LOCATION = url;
}
URL("https://www.site.com/WS.asmx?WSDL") 每 15 天更改一次,所以我需要将该 url 放入配置文件中。但我不能,因为如果我尝试将变量放入 static{} 会出现错误“无法从静态上下文中引用非静态变量名”。 我能做什么?
最佳答案
似乎您的静态初始化程序正在访问实例变量(可能是 logger
、WSEVALUARTDM_WSDL_LOCATION
)。
关于java - 从静态配置文件创建 SSL WS URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6139247/