尝试连接到 Wildfly 10.1 上的 EJB 并获取:尚未为有状态组件设置会话 ID

Trying to connect to EJB on Wildfly 10.1 and getting: Session id hasn't been set for stateful component

我正在使用以下 JNDI 配置:

    final String appName = "";
    final String moduleName = "session-beans";
    final String distinctName = "";
    final String beanName = "ItemStatefulRemote";
    final String viewClassName = ItemStatefulRemote.class.getName();
    final String toLookup = String.format("ejb:%s/%s/%s/%s!%s", appName, moduleName, distinctName, beanName, viewClassName);
    return (ItemStatefulRemote) context.lookup(toLookup);

尝试连接 stateful bean 时出现以下错误:

Session id hasn't been set for stateful component:

可能是什么原因?

因为它是有状态 bean,所以必须添加会话 ID,这可以通过使用注释 ?statefulviewClassName.

来完成

所以代码应该改为:

 final String viewClassName = ItemStatefulRemote.class.getName()+"?stateful";