【发布时间】:2019-05-30 14:30:12
【问题描述】:
我正在尝试调用静态块内的 URL 检索方法,bean 的实例化失败;嵌套异常是 java.lang.ExceptionInInitializerError。
我正在尝试从配置文件中获取 WSDL url。此配置数据存储在数据库中。
static
{
URL url = null;
WebServiceException e = null;
try
{
url = getVertexConfiguration();
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
}
private static URL getVertexConfiguration() throws MalformedURLException
{
try {
configuration = configurationDAO.getByRefName("tax/vertex",
SecureSession.getUser().getDataDomain() != null ?
SecureSession.getUser().getDataDomain() : "app.cantata");
} catch (B2BTransactionFailed b2BTransactionFailed) {
}
Map<String, DynamicAttribute> vertexTaxConfig = configuration.getConfigs();
vertexWsdlUrl = vertexTaxConfig.get("vertexWsdlUrl").getValue().toString();
return new URL(vertexWsdlUrl);
}
}
我得到静态块,bean 的实例化失败;嵌套异常是 java.lang.ExceptionInInitializerError。
【问题讨论】:
-
在类初始化期间不要做任何可能导致此类错误的事情;把这些东西放在构造函数中。 (它甚至不应该是静态的;您可能希望支持多个副本,例如用于测试。)
标签: java spring spring-boot