我正在SAP平台中使用多租户应用程序。在获取租户详细信息时,我得到了一个错误:
java.lang.ClassCastException:无法将类com.sap.cloud.account.impl.TenantContextImpl转换为接口com.sap.cloud.account.TenantContext (找到由com.sap.cloud.account加载的匹配接口com.sap.cloud.account.TenantContext )
导致此问题的代码:
public class TenantContextManager
{
public TenantContextManager() {
// TODO Auto-generated constructor stub
}
public String getCurrentAccountId() throws ServletException {
String currentAccountId;
try {
InitialContext ctx = new InitialContext();
TenantContext tenantctx = (TenantContext) ctx.lookup("java:comp/env/TenantContext");
currentAccountId = tenantctx.getTenant().getAccount().getId();
} catch (Exception e) {
throw new RuntimeException(e);
}
return currentAccountId;
}
}我在"ODataJPAServiceFactory“类实现中调用此调用的一个实例。
需要注意的一点是,我创建了一个简单的JSP应用程序,相同的代码运行正常。
发布于 2017-08-17 13:11:22
解决了这个问题。我将运行时从Java更改为JavaEE6WebProfile。看来API在Java中是不可用的。
https://stackoverflow.com/questions/45713982
复制相似问题