0

我有一个创建RuntimeFactoryApplication对象的无状态会话 bean。这两个类都是 Social Business Toolkit 的一部分。Application用于读取属性和托管 bean 文件,但这并没有发生,因为RuntimeFactory无法获取Application对象。

AbstractRuntimeFactory有一个Map对象Application

private Map<ClassLoader,AbstractApplication> applications = new HashMap<ClassLoader, AbstractApplication>();

ClassLoader使用此方法设置:

protected ClassLoader getContextClassLoader() {
    return Thread.currentThread().getContextClassLoader();
}

使用Application此方法检索对象:

public Application getApplicationUnchecked() {
    ClassLoader cl = getContextClassLoader();
    return applications.get(cl);
}

在调试过程中,我注意到 Thread id 保持不变,但是有两个不同的ClassLoader. 这是怎么发生的?只有一个会话 bean,RuntimeFactory 和 Application。getContextClassLoader() 不应该总是给我同样的对象吗?

当我工作时,我现在使用:

ClassLoader cl = this.getClass().getClassLoader();

哪里thisRuntimeFactory,但我不确定这是否是一个好的解决方案.. 感觉更像是解决实际问题的方法。

ps:我使用WebSphere Portal 作为应用服务器。

4

1 回答 1

3

在这种情况下,您不需要使用 RuntimeFactory 的东西,避免它可能更容易。去年我与另一个使用 EJB 的客户一起工作,他们选择直接实例化他们需要的端点并自己管理端点设置。代码看起来像这样:

    BasicEndpoint endpoint = new ConnectionsBasicEndpoint();
    endpoint.setUrl(url);
    endpoint.setUser(user);
    endpoint.setPassword(password);
    endpoint.setForceTrustSSLCertificate(true);

    BlogService blogService = new BlogService(endpoint);
于 2014-04-29T13:25:46.777 回答